Skip to content
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

JSON polyfill loads asynchronously in RequireJS #8

Closed
jeffrose opened this issue Oct 5, 2012 · 9 comments
Closed

JSON polyfill loads asynchronously in RequireJS #8

jeffrose opened this issue Oct 5, 2012 · 9 comments
Assignees

Comments

@jeffrose
Copy link

jeffrose commented Oct 5, 2012

While it looks like an effort has been made to load the JSON polyfill synchronously, in RequireJS it still seems to load asynchronously and therefore can be too late to provide the necessary functionality.

@unscriptable
Copy link
Member

Hey @jeffrose!

We're not attempting to load the json2 file sync. It's intentionally async. (Note: we simplified this code in the dev branch, but it's still async.)

Hmmmm.... looks like RequireJS no longer supports the priority config param. Now you have to use the shim config option, it seems. ???? Have you tried using shim?

-- John

@ghost ghost assigned unscriptable Oct 5, 2012
@jeffrose
Copy link
Author

jeffrose commented Oct 5, 2012

Okay, it was not clear to me why a promise was being used to load the JSON shim.

You are correct that the priority config is gone. So what I do instead is set dependencies on my main module.

// app.js
define( [ "poly", "has" ], ... );

The problem stems from the fact that while this works great for the referenced dependencies, e.g. poly, the JSON shim gets loaded asynchronously. So it's possible for code that uses JSON to run before the JSON shim is done loading.

@unscriptable
Copy link
Member

Ok I see. thanks for the code snippet.

Is it possible to either

a) make poly an app-wide dependency, or

b) build poly using r.js?

-- John

Sent from planet earth

On Oct 5, 2012, at 11:53 AM, Jeff Rose notifications@github.com wrote:

Okay, it was not clear to me why a promise was being used to load the JSON
shim.

You are correct that the priority config is gone. So what I do instead is
set dependencies on my main module.

// app.jsdefine( [ "poly", "has" ], ... );

The problem stems from the fact that while this works great for the
referenced dependencies, e.g. poly, the JSON shim gets loaded
asynchronously. So it's possible for code that uses JSON to run before the
JSON shim is done loading.


Reply to this email directly or view it on
GitHubhttps://github.com//issues/8#issuecomment-9180170.

@jeffrose
Copy link
Author

jeffrose commented Oct 5, 2012

a) I'm not sure offhand.

b) We'll be implementing specialized builds (old n' busted vs. new hotness) using the has API early next year, but at the moment we're not prepared to support that.

@unscriptable
Copy link
Member

I'm sure I was clear in my previous question. What I meant by (a) is:

Can you use a RequireJS shim instead of making it a dependency?

@unscriptable
Copy link
Member

Hm, wait. The version in the dev branch should work as a dependency.

https://github.com/cujojs/poly/blob/dev/json.js

Did you try that version?

@jeffrose
Copy link
Author

jeffrose commented Oct 5, 2012

Sorry, I accidentally skipped over that.

The shim configuration entry is used to treat non-AMD modules like AMD modules, replacing the wrap.js and use.js plugins.

For example...

require.config( {

    shim: {
        "qunit": {
            "exports": "QUnit"
        }
    }

} );

require( [ "qunit" ], function( QUnit ){ ... } );

So I'm not sure that putting JSON into the shim config will solve the problem.

@jeffrose
Copy link
Author

jeffrose commented Oct 5, 2012

Ok, let me take a look at the dev branch and see if that solves the issue.

@unscriptable
Copy link
Member

this fix was released in 0.5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants