Comments (6)
This may likely be a bug (need to verify), but there may be a better way to accomplish what you want to do. Have you tried using the !order suffix with the js! plugin?
curl([ 'js!sharedJs/jquery.js!order', 'js!stepOne.js!order, 'js!stepTwo.js!order' ], function()
{
$(document).ready( function(){
testOne();
testTwo();
});
},
function(){alert("something wrong")}
);
Also: be careful about the all of the $(document).ready()
calls. There's no guarantee what order these will fire in so they could be executing in the wrong order, which could cause the error you're seeing. I would remove the $(document).ready()
calls within testOne.js and testTwo.js to be sure.
Regards,
-- John
from curl.
Thank you John. I was aware of order! However, it seems not applicable to my situation. I have a collection of apps that are organized in a family tree. Javascript modules are associated with the nodes, apps with leaves. An app requires all modules between the leaf where it sits and the root of the tree. Modules need be loaded in order (from root to leaf). E.g., the root may contain jquery while code at the other nodes depends on it. Sadly, none of my codefiles are written as modules - it is all plain old javascript. New code will be different, but that is how it is. Oh, and any of these modules will consist of multiple files - otherwise the whole problem would fold down to file ordering.
As I understood, order! affects the (plain javascript) files in a module - it cannot be used to order modules.
I've experimented with the order of the requirements in the module statement. I've tried to 'chain' the modules between leaf and root (make the root a requirement for level one nodes, level one nodes a requirement for level two and so on). However, in the end it doesn't give the right behaviour. I am beginning to realize that the A in AMD carries a lot of meaning ;-)
So that is why I tried .next - it seems perfectly fit for my purposes. I might try nesting curl statements (a curl statement in the callback of another) but I can well imagine the kind of problems that might run into.
But I will look into the $(document).ready() statements. I've used a lot of them. Maybe that's where the problem is.
As a question: can I rightly infer the order of loading that is picked by Curl from the order of script statements inserted? That is, the earlier scripts are at the bottom, last script is the top one?
from curl.
John,
I fixed the issue. It's all to do with closures ;-).
Line 705 of the curl.js in the src distribution runs:
// promise chaining
api['next'] = function (names, cb) {
var origPromise = promise;
promise = new Promise();
// wait for the previous promise
origPromise.then(
// get dependencies and then resolve the current promise
function () { ctx.require(names, promise, ctx); },
// fail the current promise
function (ex) { promise.reject(ex); }
);
// execute this callback after dependencies
if (cb) {
promise.then(function (deps) {
cb.apply(this, deps)
});
}
return api;
};
The nastiness is in the origPromise.then statement. The callback refers to location "promise". However, each following invocation of .next will modify the contents of that location. So we really need to preserve it and for this we need a closure:
// promise chaining
api['next'] = function (names, cb) {
var origPromise = promise;
promise = new Promise();
// wait for the previous promise
origPromise.then(
// get dependencies and then resolve the current promise
// Joop Ringelberg: Capture promise in a closure; we'll be modifying the content of this location on following .next statements!
(function(p) {
return function () { ctx.require(names, p, ctx); }
}(promise)),
// fail the current promise
function (ex) { promise.reject(ex); }
);
// execute this callback after dependencies
if (cb) {
promise.then(function (deps) {
cb.apply(this, deps)
});
}
return api;
};
This solves the problem.
Regards,
Joop
from curl.
Thanks or bringing this to my attention, Joop! I was studying ways to implement the missing closure you noted, and it helped me realize that the api code could be simplified! Creating some tests now to verify it's fixed.
Thank you!
-- John
from curl.
Hello Joop,
Until we release 0.5.4, you can use the dev branch to take advantage of this fix.
Regards,
-- John
from curl.
Thanks John. It runs beautifully!
Joop
On 10/26/2011 07:09 AM, John Hann wrote:
Hello Joop,
Until we release 0.5.4, you can use the dev branch to take advantage of this fix.
Regards,
-- John
from curl.
Related Issues (20)
- curl-css shouldn't wait for readystate == 'complete' HOT 7
- What if the module is a function? HOT 1
- Similar functionality of curl with require.js map config? HOT 1
- Using domReady! as a dependency argument causes an error HOT 4
- dealing with the window object HOT 7
- Unhandled error is eaten by curl when bootstrap code has a json plugin dependency HOT 5
- For anyone facing the error : Multiple anonymous defines encountered HOT 1
- Multiple bundles HOT 17
- Remove old IE event listeners in domReady HOT 1
- License for curl HOT 4
- "undefined" from import when define function throws an exception HOT 8
- Modules "undefined" when error occurs HOT 1
- "new Promise()" syntax non-standard? HOT 1
- Promise.then doesn't wait HOT 5
- Add build with js plugin
- multiple anonymous defines HOT 2
- How to help curl guess the right plugin? (e.g. json! for *.json) HOT 8
- Feature Request: Add syntax to bypass plugins
- cjsm11 loader hides a TypeError and falsely reports success
- ε¦δΉ HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from curl.