You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've started implementing AMD support in enchant and its plugins. The goal is of course to support loading enchant as a fully compliant module, while retaining full compatibility with traditional loading. This has required me to:
Rewrite code that modifies global scope (very few changes).
Wrap enchant, plugins and all non-AMD dependencies in conditional module definitions.
Adapt plugins to be AMD-compliant (in a non-breaking way).
Step 3 presents a challenge (without breaking things, that is), because some plugins:
have optional dependencies (a scenario not supported in AMD by design) on other plugins, like enchant.nineleap.
modify enchant in various other places (e.g. adding new properties to enchant.Event) when loaded.
The first point is a real problem because there is no way such code can exist in an AMD module without loading those dependencies globally first. Of course, if the dependency is a plugin that also requires enchant to be loaded before it, the purpose of using AMD is lost. For this to work, I propose that code like this be implemented like the following example (simplified):
/* gl-nineleap.enchant.js (AMD use only) */define(['enchant/nineleap','enchant/gl-core'],function(nineleap,glcore){returnglcore(nineleap);});/* gl.enchant.js (for both AMD and traditional loading) */(function(factory){if(typeofdefine==='function'&&define.amd){define('enchant/gl-core',['enchant'],factory);define(['enchant','enchant/gl-core'],function(enchant,glcore){returnglcore(enchant);});}else{enchant.gl=factory(window.enchant)(window.enchant.nineleap||window.enchant);}})(function(enchant){returnfunction(parentModule){vargl={};gl.Core=enchant.Class.create(parentModule.Core,{/* ... */
return gl;};});
Work in progress can be seen in my amd-support branch. The conditional module definition wrappers have increased indentation levels by 1, so the GitHub diffs look bigger than they actually are. You might instead want to view the changes locally by running
git diff --ignore-space-change 88ecd9c HEAD
Please let me know what you think.
The text was updated successfully, but these errors were encountered:
I've started implementing AMD support in enchant and its plugins. The goal is of course to support loading enchant as a fully compliant module, while retaining full compatibility with traditional loading. This has required me to:
Step 3 presents a challenge (without breaking things, that is), because some plugins:
The first point is a real problem because there is no way such code can exist in an AMD module without loading those dependencies globally first. Of course, if the dependency is a plugin that also requires enchant to be loaded before it, the purpose of using AMD is lost. For this to work, I propose that code like this be implemented like the following example (simplified):
Work in progress can be seen in my amd-support branch. The conditional module definition wrappers have increased indentation levels by 1, so the GitHub diffs look bigger than they actually are. You might instead want to view the changes locally by running
Please let me know what you think.
The text was updated successfully, but these errors were encountered: