JavaScript - YUI Namespacing proposal

JavaScript - YUI Namespacing proposal

by Andrew Lyons -
Number of replies: 4
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

To complement the Coding style discussion, I've also been looking at our current namespacing for YUI modules. 

In essence, this proposal seeks to move all YUI modules to the Y namespace, whilst still keeping things short, and simple. It also attempts to rigidly codify the structure of this namespace so that you can determine the correct location for any code that you add.

We would benefit from moving all of our YUI Moodle code to the Y namespace as this would give us improved code isolation between different Modules. That is to say that, if moodle-form-dateselector adds a method to Y.Node, it is only present to moodle-form-dateselector and not in any other use of Y.Node on the same page.

I've written a proposal on the developer wiki, and would appreciate any feedback others may have.

In brief, the proposal is to use a namespace of:

   Y.M.<plugin_or_system_type>[_<component>].<YUI_modulename>[.<YUI_submodule>]

Examples include:

Y.M.core.dock
Y.M.core.dock.loader
Y.M.block_navigation.navigation
Y.M.mod_assign.inlinereply
Y.M.form.dateselector

I've raised an issue in the tracker to discuss this proposal in MDL-43216.

Thank you in advance,

Andrew

Those links again:

Average of ratings: Useful (2)
In reply to Andrew Lyons

Re: JavaScript - YUI Namespacing proposal

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Conceptually would this then in future ring fence all Moodle YUI JS code such that if a new framework was ever adopted, say the Acme JS Framework (AJF) then migration would be easier?  For example: A.M.core.dock.

In reply to Gareth J Barnard

Re: JavaScript - YUI Namespacing proposal

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

That isn't really the purpose - it's more to allow us to benefit from the YUI sandboxing features, but it has the added benefit of scoping all Moodle JavaScript to a single namespace which I imagine would help if changing our framework was on the cards (which it isn't). We should codify the namespace though to make it easier to know where your code should live, and to simplify things.

Average of ratings: Useful (1)
In reply to Andrew Lyons

Re: JavaScript - YUI Namespacing proposal

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thanks Andrew.  I had no intent of starting the whole YUI debate again, was just asking the question of what benefits it would bring (as I did not initially understand them) and keeping an open mind.

In reply to Gareth J Barnard

Re: JavaScript - YUI Namespacing proposal

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

That isn't really the purpose - it's more to allow us to benefit from the YUI sandboxing features, but it has the added benefit of scoping all Moodle JavaScript to a single namespace which I imagine would help if changing our framework was on the cards (which it isn't). We should codify the namespace though to make it easier to know where your code should live, and to simplify things.