-
Notifications
You must be signed in to change notification settings - Fork 5.3k
AMD support #1029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AMD support #1029
Conversation
|
||
var uuid = 0, | ||
var coreUuid = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some "global" variables need to be renamed, so they don't clash in the final bundle jquery-ui.js
(because, each file UMD wrapper gets removed for optimization).
Shall we rename them case-by-case like the above, or shall we be more programmatic and follow some kinda pattern through all the files that prevents them from clashing? Eg. by using key-value pairs objects:
var core = {
uuid: 0,
...
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither. The variables shouldn't be global. We'll need to just address these on a case-by-case basis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, all the current clashing ones have been renamed here 13be9a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scott, do you want those globals to be addressed as part of this PR? Or handle them later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're mimicking the build process of modernizr, which uses requirejs to merge the parts into the bundle; plus it processes the files, so each individual AMD wrapper (in our case UMD) is removed.
We need to address those globals here, or we'll have a problematic bundle js. :(
Hey @rxaviers. I gave this branch a shot and only noticed one thing:
Seems like the The only other thing I noticed is that the...
comments in the code are redundant now. Should we remove them? |
It shouldn't, because autocomplete or any other component doesn't return anything, they just extend require.config({
paths: {
jquery: "path/to/jquery",
jqueryui: "path/to/jquery-ui"
}
});
require([ "jquery", "jqueryui/jquery.ui.autocomplete" ], function( $ ) {
$.fn.autocomplete === undefined; // should be false
}); Does it make sense? |
Indeed they are redundant. I vote to remove them 👍 |
Regarding the return value for the module, @arschmitz and I are already planning on making the widget factory return the generated constructor. Once we do that, we should be able to just have: return $.widget( "ui.plugin", { ... } ); The dependency comments should go away. |
I meant to respond to some comments around named modules, but looks like they are now classified as "outdated". Just to confirm then: Named modules (define() calls with the first argument a string for that module's ID) should be avoided. If all of these modules are in a directory, say called 'jqueryui', then if that directory is either placed at the AMD loader's baseUrl, or if there is a paths config set up for 'jqueryui' then it should all work out. Consumers of these modules would use IDs like 'jqueryui/jquery.ui.autocomplete' to refer to these modules. |
jquery-ui depends on jquery. When defining the components, we do require.config({
paths: {
jquery: "path/to/jquery"
}
}); Unless they have a |
@rxaviers that is correct, either a paths config for 'jquery' or 'jquery.js' in the baseUrl. There are fancier options like map config, but for single file JS dependencies, just paths config or ideally just dropping jquery.js in the baseUrl should be the encouraged routes. |
@jrburke Here is the link for the other discussions: #1029 (comment) |
@jrburke Excellent! Thanks. It would be awesome if you could bless these two files: (so, I am safe this change is good) PS: basically, I'd like you to check the |
@rxaviers those files look fine to me. |
thanks! |
@scottgonzalez Excellent. I would expect (and want) that. |
Making Might as well implement that as part of this PR. |
At the meeting yesterday we discussed that the build task here is just for size comparisons, since everything else moved to DB. It looks like a lot of this PR would be unnecessary without that build task. Not that the work has been a waste of time, but the actual building needs to be implemented in DB, not here, right? Maybe we should land that cleanup and the widget-returns-constructor change before this PR, then rebase. |
var contents = grunt.file.read( filepath ).replace( /define\("(main|jquery-ui)", function\(\)\{\}\);/g, "" ); | ||
|
||
// Remove the mysterious semicolon `;` character left from require([...]); | ||
contents = contents.replace( /\/\/ mysterious semicolon.*/g, "" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the regex literally contain "mysterious semicolon"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sure I remove the right thing.. But, the idea is to figure out why this is happening and fix the root cause :P
Please don't make the return value part of this PR. It will need to happen much sooner than this is going to land. I will land it when @arschmitz has finished a proof of concept in the Mobile repo. |
When the rest of the discussion settles down, we need to talk about tracking CSS dependencies. But I don't want to discuss that until there are fewer other discussions going on. |
Right, the build would be "moved" to DB. We'd only land the new UMD wrapped source files (knowing they work). Will let you guys know when it's updated. |
The biggest cons of removing the build task is that we are not able to jshint the final output on each commit anymore. Therefore, it's hard to know whether variables among components might clash. |
DownloadBuilder is ready to build these UMD files jquery/download.jqueryui.com#156 |
By the way, thanks for the review and fixes. |
Rebased. PS: Just figured out why git didn't revolve the rename automatically. Because, it's not a simple rename, it's a rename plus content changes (from |
Ah, that makes sense. |
We really need to expose |
Is this going to happen before or after 1.11? |
I'd like to do it before 1.11. |
Ok, thanks. I will add one issue to handle that on DB. |
Changes, per @scottgonzalez review, complete. |
- By executing https://gist.github.com/jzaefferer/893fcf70b7eebc1dc271; Fixes #9464 Ref #1029
- By executing https://gist.github.com/jzaefferer/893fcf70b7eebc1dc271; Fixes #9464 Closes gh-1029
Ref #9464 Ref gh-1029
Ref #9464 Ref gh-1029
Ref #9464 Ref gh-1029
- By executing https://gist.github.com/jzaefferer/893fcf70b7eebc1dc271; Fixes #9464 Closes gh-1029
http://wiki.jqueryui.com/w/page/66995889/AMD-Support
After merging to master:
$.Widget
.Skip