Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convince me to switch from YUI 2 to YUI 3

Tags:

javascript

yui

I've been using YUI Library to develop websites. YUI 3 came out on september.

I'm still not convinced if i have to prepare myself for a migration.

What are the advantages of 3rd version over the 2nd ?

Have you been involved in such a migration, lately ?

like image 914
Arno Avatar asked Dec 18 '09 15:12

Arno


3 Answers

I have not been involved in a migration, but I have contributed to the YUI 3 gallery, and I also know there is a gallery entry that allows any class from YUI 2 to be used in YUI 3. I guess the main advantage of YUI 3 is the ability to load in what you want on demand. You include 1 javascript file, and then would use the following line to use whatever modules in yui you want.

YUI().use('dom',function(){
 // your code here
});

The advantage of this is it laods the DOM module, and makes available ONLY in the scope of that function. This is good because it only loads the modules you want in a specific scope. This will prevent clashes with any other JS frameworks if you use them.

If you want to add your own custom module you would do something like this

YUI().add('mycustompackage',function(Y){
    MyCustom.package.SomeClass = function(){}
    MyCustom.package.SomeClass.prototype = {}
},'1.0.0',{requires:['base','dom','event'],use:['node']});

That will add your module, and register the dependencies, so then you can use it by saying

YUI().use('mycustompackage',function(){
 // code goes here
});

I guess from what I can see, the main advantages are a more secure and portable framework. You can make the YUI 3 modules available ONLY within a given function scope. THis frees up the main scope of the page for other things if you wish. Its also more secure, the definition of your functions are in a private scope, so they have no global variable hooks to be exploited by say script injection or what not.

like image 116
Zoidberg Avatar answered Oct 07 '22 02:10

Zoidberg


Arno -- here's my answer:

http://developer.yahoo.com/yui/theater/video.php?v=miraglia-yuiconf2009-yui3

Here's Luke's answer (even better!):

http://developer.yahoo.com/yui/theater/video.php?v=smith-yuiconf2009-events

Oh, and Todd's answer (also fantastic):

http://developer.yahoo.com/yui/theater/video.php?v=kloots-yuiconf2009-sugar

YUI 3 is a big step forward for us -- we're really excited about the basic architecture, and what we're hearing from people who are making the migration is that they love the YUI 3 experience. We need to get the widgets going on 3, but we're working on that (see http://developer.yahoo.com/yui/theater/video.php?v=desai-yuiconf2009-widgets ).

I'm not remotely objective, but I hear good things from those who are.

-Eric

like image 44
Eric Miraglia Avatar answered Oct 07 '22 02:10

Eric Miraglia


There's no need to migrate. You can start using YUI 3 right along side YUI 2, and I encourage you to do so.

I'm very impressed with the ideas and architecture behind YUI 3. For example how YUI 3 normalizes node and event handling and how custom events are handled like native events.

The modularity of the library not only makes it easier to use but promotes the writing of more modular code yourself, which is a good thing.

Take a look at Eric's introduction video and all the other YUI 3 videos at the YUI Theater to see more reasons to make the switch.

like image 26
frglps Avatar answered Oct 07 '22 01:10

frglps