Posting in these forums is disabled. These forums will be available for archive purposes. Please join the new forums at the links below:
|Page 1 of 1||[ 7 posts ]|
The core of today's Open Hours topic was AMD modules, and as I mentioned during the meeting, we'd love to hear from the community on a few things:
A) Is there interest in supporting the standard?
B) How would you like to use them? AMD modules loaded with YUI, or YUI as AMD modules?
C) Are there any approaches you've taken so far to integrate them within your YUI application?
Here's a gist of the notes I shared during the OH.
And here is the demo of RequireJS as a YUI module being used to include AMD modules. Yes, it's not an optimal solution, it just provides a playground for AMD+YUI.
http://derek.io/~/derek.github.com/sand ... index.html
It's late and there's a lot to discuss, but I want to give leave a couple of thoughts.
YUI's module system is awesome. And it's more awesome considering that it was released a lot before the community realized it needed modules. It's more powerful than AMD/CJS2.0 with very little complexity added to the code, but with more to grasp conceptually. However, I think most developers will find AMD more intuitive.
Having said that, while I agree with whoever (I think it was Luke) said that there's no harm in having competing approaches, there are certain use cases in which AMD support of some kind would be great. Consider the following:
- I have a project in which I want to use a certain module, for example socket.io
- Managing socket.io's versions is a breeze with NPM
- Let's say socket.io uses AMD (I think it doesn't)
To avoid wrapping socket.io by hand with a YUI.add() call each time I update it, it would clearly be very useful to do YUI().use('socket.io') and have it just work.
I have started to write a short script that let's you do that, but I haven't finished it yet. I'll post it when it works.
jdopazo: if you mean having a script that can wrap CommonJS-like modules like socket.io into AMD, the requirejs optimizer has a converter:
node r.js -convert path/to/commonjs/dir output/dir
There is a little bit more info in the readme if you look for "-convert": https://github.com/jrburke/r.js
I am interested to see if the YUI loader could load AMD modules and have them show up on the Y instance, something like indicated in this gist:
I am willing to take a look at making some sort of adapter that could fit in with the YUI loader -- something that hopefully could use the YUI loader internals to set up the scripts, but set up the define() API so that it could accept an AMD module and bind it to the Y instance. Maybe just start with named AMD modules not anonymous ones, just to make it easier to start.
However, I am very new to the YUI code internals, any pointers would be helpful. I likely will not have time to do a proper deep dive on the code for a while, but if anyone has pointers I would likely go quicker.
I would be happy to give you a hand with the Loader internals
I thought about doing Y[moduleName] = module, but if the module is an object, don't you think it would be better to mix it into the Y instance? Would it be confusing if some modules appear as Y[moduleName] and others don't?
Getting this to work using the patterns configuration was surprisingly easy. There are some features needed from Loader, like regular expressions for patterns.
amdClick here to see the revision history on this Gist.
|Page 1 of 1||[ 7 posts ]|
|You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum