cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

Unable to dynamically append paths in curl 0.7.2 #146

Closed dizzib closed 11 years ago

dizzib commented 11 years ago

In curl 0.6.2 I'm able to update curl paths at runtime like so:

cfg.paths.foo = '/bar'
curl cfg

This no longer works in 0.7.2, neither does the following suggestion from #143:

curl { paths: { foo: "/bar" } }

which seems to blat any existing paths, resulting in subsequent 'Syntax or http' errors.

Cheers! Andy.

dizzib commented 11 years ago

Ok I think paths aren't being augmented because the Begetter only mixes in at the root level:

for (var p in mixin) child[p] = mixin[p];

So I guess I'd need to pass the new path mixed-into the original paths ? However this doesn't seem to work.

On further toying, I've discovered passing in an identical original config causes subsequent 404s:

myconfig = curl = { ... }       // setup
curl(...)                       // 1st call ok

curl(myconfig)                  // 2nd call problematic ?

Not sure if I'm missing something, ta!

unscriptable commented 11 years ago

Yep. I have confirmed this bug and will fix it in the next release. -- J

On Wed, Nov 7, 2012 at 9:28 AM, Andy notifications@github.com wrote:

Ok I think paths aren't being augmented because the Begetter only mixes in at the root level:

for (var p in mixin) child[p] = mixin[p];

So I guess I'd need to pass the new path mixed-into the original paths ? However this doesn't seem to work.

On further toying, I've discovered passing in an identical original config causes subsequent 404s:

myconfig = curl = { ... } // setup curl(...) // 1st call ok

curl(myconfig) // 2nd call problematic ?

Not sure if I'm missing something, ta!

— Reply to this email directly or view it on GitHubhttps://github.com/cujojs/curl/issues/146#issuecomment-10149787.

dizzib commented 11 years ago

Cool, thanks!

dizzib commented 11 years ago

Hi John, thanks for fixing this issue.

Just to confirm I've got it working but only with a workaround :)

With wire 0.9.0 and curl 0.6.2 the following sequence was working:

curl
curl wire!parent
curl augmented-paths
deferred wire child relying on augmented-paths

The final step fails after upgrading to curl 0.7.3 as if it's still using the original-paths rather than augmented-paths.

My workaround is to swap the order of steps 2 & 3:

curl
curl augmented-paths
curl wire!parent
deferred wire child relying on augmented-paths

Not a big deal for me, just thought I'd mention it. Cheers!

unscriptable commented 11 years ago

Ah, good point Andy!

curl effectively uses a snapshot of the config when a module is loaded. I didn't think it made much sense to change the config after a module is loaded. I think there are plenty of reasons for snapshotting (is that a word even?).

Deferred wiring is certainly a special case and one that I am sure we'll revisit again. Thanks so much for the feedback!