User:Owyn/AMD And Promises

From MediaWiki.org
Jump to navigation Jump to search
Request for comment (RFC)
AMD And Promises
Component General
Creation date 2013-11-20
Author(s) Owen Davis
Document status draft
General2013-11-20Owen Davisdraft

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.