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

Fix 1530 - Asynchronously load scripts with JSX transformer #1558

Merged
merged 1 commit into from
May 18, 2014
Merged

Fix 1530 - Asynchronously load scripts with JSX transformer #1558

merged 1 commit into from
May 18, 2014

Conversation

nhunzaker
Copy link
Contributor

I was kind of curious about how this script worked, so I took a stab at #1530. The implementation is fairly simple, an enhancement would be to load all of the script tags in parallel and then run them sequentially.

But, this gets the waterfall without synchronize requests on an example I had:

screen shot 2014-05-18 at 3 28 43 pm

Also, I wasn't able to find tests for this script, do any exist?

}
});
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: semicolon is unnecessary here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nixed, (amended to commit)

@sophiebits
Copy link
Collaborator

There aren't any tests for this, no. It would be cool to load the scripts in parallel but run them in order, but this is fine too.

@@ -150,7 +150,7 @@ var load = exports.load = function(url, callback) {

// Disable async since we need to execute scripts in the order they are in the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, can you update this comment too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// async, however scripts will be executed in the order they are in the
// DOM to mirror normal script loading.

sufficient?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that sounds good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@syranide
Copy link
Contributor

Isn't this executing them in arbitrary order?

@sophiebits
Copy link
Collaborator

@syranide tick is executed in the onreadystatechange callback.

@sophiebits
Copy link
Collaborator

@nhunzaker Thanks!

sophiebits added a commit that referenced this pull request May 18, 2014
Fix 1530 - Asynchronously load scripts with JSX transformer
@sophiebits sophiebits merged commit 66291d2 into facebook:master May 18, 2014
@nhunzaker
Copy link
Contributor Author

@spicyj Glad to help! I have another branch out that loads scripts in parallel. I tried to keep things minimal, what are your thoughts on this?:

https://github.com/nhunzaker/react/compare/jsxtransform-parallel?expand=1

@sophiebits
Copy link
Collaborator

@nhunzaker Looks pretty reasonable at a first glance. It might be nice to run scripts as soon as they're loaded if all the scripts before them have also loaded (but not if it'd add a lot of code complexity). Either way, could you open a PR with this when you're ready so I remember to look at it?

Thanks!

@fleaflicker
Copy link

Is there a way to listen for JSXTransformer to finish processing all scripts? Previously I could add another onload listener and be guaranteed that it executed after JSX scripts were executed. That's no longer possible after this change.

Any ideas? In my development environment, I have my UI logic in a jsx file and my app in a separate JS file which can only call React.renderComponent after the jsx file is processed.

@syranide
Copy link
Contributor

You shouldn't really use JSXTransformer for anythimg serious at all. Use ./jsx --watch (super simple) or browserify/webpack instead.

@sophiebits
Copy link
Collaborator

@fleaflicker Not currently, though it's possible we could add something for that if you open a separate issue, but if you load your second (pure-JS) file with JSXTransformer as well (using type="text/jsx") then it'll be run after the first one loads.

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

Successfully merging this pull request may close these issues.

5 participants