Re: [Wikitech-l] resource loader; 1.32 alpha; 1.32 stable breaking change, loading scripts in widgets
I agree with Bartosz Dziewoński. However, after checking out the code, I think the reason why I need to change the RLQ push statements is due to the resources/src/mediawiki.base/mediawiki.base.js modifications in v1.32 stable. window.RLQ = { push: function ( entry ) { if ( typeof entry === 'function' ) { entry(); } else { mw.loader.using( entry[ 0 ], entry[ 1 ] ); } } }; It seems hacky, but when using RLQ.push() and mw.loader.using in widgets I now have to use RLQ.push([ [], function () { mw.loader.using('mymodule'); }); Otherwise mw.loader.using won't be defined as the anonymous function is executed instantly (why mw.using.loader is not available globally yet at this time I dont know for sure). ___ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Re: [Wikitech-l] resource loader; 1.32 alpha; 1.32 stable breaking change loading scripts in widgets
I don't know if its best practise to do this, but core seems to do: (window.RLQ=window.RLQ||[]).push(function () { mw.loader.using('ext.myextension').then(function(){ console.log('library loaded');}); }); You probably don't have many other options if you are using the Widgets extension. -- Brian On Thu, Apr 4, 2019 at 4:08 PM Bartosz Dziewoński wrote: > Best practice is to use the PHP methods which generate the required > wrappers. Have a look at ResourceLoader::makeLoaderConditionalScript() > and ResourceLoader::makeInlineCodeWithModule(). > > Alternatively, if it's possible, it is ideal to put the initialization > code into another module and load it with addMobules() etc. as usual, > instead of inlining the code in the HTML source. > > -- > Bartosz Dziewoński > > ___ > Wikitech-l mailing list > Wikitech-l@lists.wikimedia.org > https://lists.wikimedia.org/mailman/listinfo/wikitech-l ___ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Re: [Wikitech-l] resource loader; 1.32 alpha; 1.32 stable breaking change loading scripts in widgets
Best practice is to use the PHP methods which generate the required wrappers. Have a look at ResourceLoader::makeLoaderConditionalScript() and ResourceLoader::makeInlineCodeWithModule(). Alternatively, if it's possible, it is ideal to put the initialization code into another module and load it with addMobules() etc. as usual, instead of inlining the code in the HTML source. -- Bartosz Dziewoński ___ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
[Wikitech-l] resource loader; 1.32 alpha; 1.32 stable breaking change loading scripts in widgets
dear all, i experienced breaking changes when loading scripts in the widgets extension through the resource loader. please check the gitlab snippet [1] i created. i did not find any documentation and checked the migration guide [2]. is the code presented in the gitlab snippet good practice? could anyone point me to existing documentation? thank you! tom [1] https://gitlab.com/snippets/1843172 [2] https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users)#MediaWiki_1.32_(TBA) ___ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l