YUI2 - 2in3 replacement proposal

YUI2 - 2in3 replacement proposal

by Petr Skoda -
Number of replies: 8
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers

Hello,

I would like to propose changes in current support of YUI2 library in Moodle which was already deprecated two years ago. The major problem is that YUI2 javascript and CSS are loaded on each page, another problem is that our hacky YUI2 support sometimes breaks during upgrades to new YUI3 versions. Related internal changes may also allow us to make more performance optimisations in the future.

MDL-34741 contains a patch that replaces our current loader hacks with YUI 2in3.

The benefits should be:

  1. YUI2 Javascript classes and CSS are not loaded on each page - performance

  2. YUI2 files are loaded asynchronously - performance

  3. cleaner coding style with fewer bugs

Necessary upgrade steps:

  1. none for YUI3 code

  2. YUI3 code using YUI2 widgets needs to use Y.YUI2.* instead of previous YAHOO.*

  3. rewrite old legacy code that is still using deprecated $PAGE->requires->yui2_lib('xx') to use new moodle JS modules

  4. in the worst case just wrap old code with: YUI().use('yui2-dom', 'yui2-event', '...', function(Y) {var YAHOO = Y.YUI2; ...old code here...});

If you need more examples see https://github.com/skodak/moodle/compare/master...wip_MDL-34741_m24_yui2in3

Are there any objections? Do you still use YUI2 in your modifications and plugins? I agree that this may be a bit problematic especially for unmaintained contrib plugins.

Petr

Average of ratings: Useful (3)
In reply to Petr Skoda

Re: YUI2 - 2in3 replacement proposal

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I assume this is for Moodle 2.4?

Any place where I still use YUI2, I think it woudl be good to update the code to YUI3, but I don't necessarily have the time to do that.

In reply to Tim Hunt

Re: YUI2 - 2in3 replacement proposal

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Sure, 2.4dev only (to be released in December 2012), that should hopefully give everybody enough time to upgrade the code (including OU custom plugins).
In reply to Petr Skoda

Re: YUI2 - 2in3 replacement proposal

by Tony Levi -

To put it simply... YES PLEASE.

Let YUI2 begone at last - loading both of these has been madness.

In reply to Tony Levi

Re: YUI2 - 2in3 replacement proposal

by Dan Poltawski -
Well - I agree.

But this proposal doesn't actually completely get rid of YUI2.

From third-party developer point of view you'd need to update your code to use 2in3. In moodle core does that mean we have to support YUI2 forever? If not, third party developers would be forced to update their code again.

So, is it worth doing this intermediary step (breaking third party plugins) if we can't get rid of YUI2 completely?
In reply to Dan Poltawski

Re: YUI2 - 2in3 replacement proposal

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
The point is to get rid of YUI2 completely from 95% of pages loads, 2in3 allows us to let the YUI2 sit idly on the server only. I updated the code to use 2in3 everywhere because it took me only 1 day. I would need several weeks to convert to YUI3, but yes I think we should do it gradually before 2.4 release.
In reply to Dan Poltawski

Re: YUI2 - 2in3 replacement proposal

by Matt Gibson -

There are still a lot of YUI2 widgets that still don't exist in YUI3 e.g. contextmenu and treeview. I would have to spend weeks rewriting stuff if YUI2 went away, although I've mostly transitioned to 2in3 now.

I don't understand why these widgets have just been left without being upgraded by the YUI team. Makes me think that jQuery would be worth looking into just for the long term stability.

Average of ratings: Useful (2)
In reply to Matt Gibson

Re: YUI2 - 2in3 replacement proposal

by Hubert Chathi -

jQuery-ui has less built-in widgets than YUI.  For example, jQuery-ui doesn't have a built-in treeview or context menu.  So switching from YUI to jQuery because YUI3 doesn't have contextmenu and treeview wouldn't make any sense.

In reply to Hubert Chathi

Re: YUI2 - 2in3 replacement proposal

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

The key words here are "built-in". JQuery seems to have an abundance of third party widgets. So it was very easy to find a Jquery tree view i.e.

http://jquery.bassistance.de/treeview/demo/

Third party is not attractive as core in terms of support, but I would not bet the farm on Yahoo support for YUI for the lifetiime of the Moodle project.

I was recently attempting to write some drag and drop code for a Moodle project. I already know and teach JQuery but I thought I'd attempt to keep to the standards and see how I could do it in YUI/Javascript. How hard could it be?, other projects already have done this type of thing.

To cut a tedious story short. I did it in JQuery.