User:Owyn/AMD And Promises
AMD And Promises | |
---|---|
Component | General |
Creation date | |
Author(s) | Owen Davis |
Document status | in draft |
MediaWikiâs Javascript stack is currently defined using a generic namespace/modules approach, Wikia has successfully adopted the AMD transport for the same purpose; the latter is a CommonJS standard and a well recognized pattern throughout the industry to define testable units that enforce explicit dependency declaration and injection by design and is compatible with many 3rd party libraries (e.g. jQuery, Lodash, etc.).
Wikia has also invested in integrating the CommonJS Promise pattern in all the code dealing with asynchronous operations to standardize its use and avoid the famous âCallback Hellâ issue that this kind of code usually leads to in Javascript, the current implementation adopted is jQueryâs Deferreds which is fully compliant with the CommonJS specification as implemented in many libraries and frameworks nowadays; MediaWiki uses its own chainable hook handlers implementation (mw.hook) also for this purpose.
Switching to those two modern, well known and established standards would yield a higher degree of interoperability with 3rd party JavaScript code and lower the learning curve for new front-end developers.