Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

YUI/Namespacing: Difference between revisions

From MoodleDocs
m (Protected "YUI/Namespacing": Developer Docs Migration ([Edit=Allow only administrators] (indefinite)))
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{draft}}
{{Template:Migrated|newDocId=/docs/guides/javascript/yui/namespacing}}
{{Work in progress}}
{{Moodle 2.7}}
 
== Introduction and Rationale ==
 
One of the many fabtastic features of YUI is that it supports sandboxing of individual modules. This means that a third-party plugin cannot interfere with core plugins in such a way that will have undesired consequences to anything using the core code.
 
As an example, a plugin could modify Y.Node to add a new function, or overwrite an existing function. This may be desirable for one instance of that Node, but undesirable for all others. For anyone wishing to use the additional function, they should depend upon the plugin instead which adds this functionality.
 
To benefit from this sandboxing fully however, we must write our YUI modules under the Y namespace.
 
To keep things consistent and clear, all Moodle-specific modules should be under a single Namespace. Ideally this namespace should be short, but still clear that it relates to Moodle.
 
== Proposed namespace ==
 
The proposed namespace fits into:
 
    Y.M.<plugin_or_system_type>[_<component>].<YUI_modulename>[.<YUI_submodule>]
 
The '''plugin_or_system_type''' should match the list defined in lib/classes/component.php in fetch_subsystems, with the additional 'core' subsytem used to for items within lib.
 
The ''optional'' '''component''' will be the plugin name where relevant
 
The ''' YUI_modulename''' should match module name
 
The ''optional'' '''YUI_submodule''' should match the submodule if relevant
 
== Examples ==
 
{|
| YUI Module || Namespace
|-
| moodle-core-dock || Y.M.core.dock
|-
| moodle-core-dock-loader || Y.M.core.dock.loader
|-
| moodle-course-toolboxes || Y.M.course.toolboxes
|-
| moodle-mod_forum-inlinereply || Y.M.mod_forum.inlinereply
|-
| moodle-block_navigation-navigation || Y.M.block_navigation.navigation
|-
| moodle-mod_assign-history || Y.M.mod_assign.history
|-
| moodle-form-dateselector || Y.M.form.dateselector
|-
| moodle-form-listing || Y.M.form.listing
|}

Latest revision as of 12:47, 9 December 2022

Important:

This content of this page has been updated and migrated to the new Moodle Developer Resources. The information contained on the page should no longer be seen up-to-date.

Why not view this page on the new site and help us to migrate more content to the new site!