Skip to content

Comments

[4.0] WebAssetRegistry Improve dependency handling#22741

Merged
wilsonge merged 4 commits intojoomla:4.0-devfrom
Fedik:asset-deps
Oct 26, 2018
Merged

[4.0] WebAssetRegistry Improve dependency handling#22741
wilsonge merged 4 commits intojoomla:4.0-devfrom
Fedik:asset-deps

Conversation

@Fedik
Copy link
Member

@Fedik Fedik commented Oct 20, 2018

This is update to #22435

Summary of Changes

Now the WebAssetRegistry shows a correct state of dependency, even before attach happen. So the asset state active/inactive should be correct at any time.

Also I have improved dependency calculation, to use Topological sorting.

Testing Instructions

Run somewhere:

$waInst = new \Joomla\CMS\WebAsset\WebAssetRegistry;
$waInst->setDispatcher($app->getDispatcher());
$waInst->addAsset(new \Joomla\CMS\WebAsset\WebAssetItem('mother'));
$waInst->addAsset(new \Joomla\CMS\WebAsset\WebAssetItem('father'));
$waInst->addAsset(new \Joomla\CMS\WebAsset\WebAssetItem('child1', ['dependencies' => ['mother', 'father']]));

$waInst->enableAsset('child1');

var_dump($waInst->getAsset('mother')->isActive());
var_dump($waInst->getAsset('father')->isActive());
var_dump($waInst->getAsset('child1')->isActive());

$waInst->enableAsset('mother');
$waInst->disableAsset('child1');

var_dump($waInst->getAsset('mother')->isActive());
var_dump($waInst->getAsset('father')->isActive());
var_dump($waInst->getAsset('child1')->isActive());

Expected result

true
true
true

true
false
false

Actual result

false
false
true

true
false
false

@mbabker one more review? 😉

ping @mbabker @wilsonge

Additional question:

Need to decide how to use assets in layouts and other parts of the CMS.

Current ways are:

Factory::getDocument()->getWebAssetManager()->enableAsset('fooBar');

Factory::getContainer()->get('webasset')->enableAsset('fooBar');

Factory::getContainer()->get('webasset') - does not depends from a request, and can be run at any time of execution, that I like
Factory::getDocument()->getWebAssetManager() - depends from request, and can be run only "afterRoute"

what could be better, any ideas? something "between" these two.

@mbabker
Copy link
Contributor

mbabker commented Oct 20, 2018

Factory::getDocument()->getWebAssetManager() - depends from request, and can be run only "afterRoute"

Good. Plugins that are arbitrarily trying to load media in onAfterInitialise are problems anyway. Media loading shouldn't be allowed until we know the request format, the current API makes it way too easy to force HTML format if you are crazy enough to try a non-HTML outputting request.

@wilsonge wilsonge merged commit 6fa9f7e into joomla:4.0-dev Oct 26, 2018
@wilsonge
Copy link
Contributor

Thanks!

@wilsonge wilsonge added this to the Joomla 4.0 milestone Oct 26, 2018
@Fedik Fedik deleted the asset-deps branch October 26, 2018 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants