-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Javascript host environment documentation #335
Comments
I agree that there could be some better documentation around this. For example, the "light" implementation of the CommonJS module system, should be documented, if it's not already. (stuff is moving so quickly, it's hard for me to keep track of it all) |
+1 |
We always need more docs! For testing in the full environment, check out the "Testing" section of the documentation - we have a harness for integration testing that should help you do what you want.
|
@aackerman can you list the issues you ran into by trying to use Bluebird? Maybe we can fix those quickly. |
I can give more detailed info about the issue with bluebird later tonight, but in the mean time, having installed bluebird with |
Can you give the exact error? Also note that there's a Promise global already existing in React Native |
It looks like a clear issue with bluebird from what I can tell. The block in
It's clearly throwing an error because the DOM is not available, but it's interesting that @vjeux as you said a Promise implementation does exist already, and what I really wanted just simply I'll make a ticket on the |
Yeah, all those feature detection needs to be carefully considered when running in a different environment. The implementation of Promise that we have is using setImmediate that has been implemented to run before we hand back the process to obj-c |
By the way, fetch is there by default. It has a much nicer api than xhr :) |
|
This is where we mangle with the global environment. We should probably do One issue if we do this is that it's now going to use setTimeout(0), which is going to do a round trip to native for every single call. Since when you are using promises, you tend to chain a lot of then, it's going to be much slower than needed. It really needs to use setImmediate. |
I can add setImmediate check after the MutationObserver check, np :) |
Okay perfect. I'm trying to remove MutationObserver right now, I'll report back in 2 minutes |
Bingo, it's working, it now falls through the setTimeout check. I'm sending an internal diff, it'll be updated in the next version. |
setImmediate check published in 2.9.16 |
That was fast ;) |
yea the upside of lone cowboy projects :p |
Since I got you, I'd like to get your opinion on This is the promise implementation that we're providing. Do you think it makes sense to use bluebird by default? |
Well I don't personally find the pure ES6 api enough for application development, I find stuff like |
Yeah, at Facebook we use a slightly improved version of Promises with .finally and .done https://github.com/facebook/react-native/blob/master/Libraries/vendor/core/Promise.js#L42 Don't have the rest though. I'll poll people internally and see what they think. |
The warnings about uncaught promise rejections are the number 1 reason to use bluebird over the specced ES6 promises. Trying to find silently swallowed errors is developer hell. |
If I was intent on finding out more about the JS host environment is here the best place to look? |
Awesome thanks, I'll do some reading and see if I can distill some of the information. |
btw I checked the finally implementation - just a note that |
@vjeux I think you really want to have long stack traces, unhandled rejection detection and better aggregation methods in your promises. You can always just use a special build of bluebird. Facebook already has groups using bluebird internally (namely WhatsApp Web), I think having a robust promise implementation would be really nice for react native. (That said, things like a TableView would matter a lot more to me as a user :P) |
Is there a special build of bluebird that's compliant with the es6 spec? Aka not adding extensions such as finally? |
@vjeux you can remove extensions if you really want to beyond the most partial build (or just not use them) but why? Stuff like You can get bluebird down in a partial build to ~5kb but to be fair the extra stuff that makes bluebird bigger has huge usability gains. |
I'm not sure I see the point of such a build - there is literally thousands of es6-promise shims available already |
@petkaantonov well, the general idea is to get the wins from bluebird like long stack traces and more debuggable and faster promises in react-native I think. |
Those are not compliant with es6- spec |
So what? React is not world renowned for sticking to strict ES6 it's known for making pragmatic choices in order to make developer life easier. Adding long stack traces and enabling debuggable promises would be a huge deal. |
React native environment should look like the browser / node. By putting non standard primitives as global we would break all the existing code out there. This would be bad for the entire ecosystem. In this case, people can just npm install bluebird to get all those non standard behavior if they want to |
…detection Summary: Bluebird is checking if MutationObserver exists and if it does, uses it and instant crashes. Since we don't have the DOM, MutationObserver doesn't make sense. Also, pretty cool thing, the bluebird maintainer updated the feature detection to fallback to setImmediate before checking setTimeout. He committed and made a new version in less than 5 minutes! facebook#335 (comment) Test Plan: Run bluebird and make sure it runs with setImmediate
I believe that this is covered in this doc now: https://facebook.github.io/react-native/docs/javascript-environment.html#content |
Summary: Followup of #335, fix #326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
Summary: Followup of facebook#335, fix facebook#326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`. Closes facebook/yoga#344 Reviewed By: dshahidehpour Differential Revision: D4459950 Pulled By: emilsjolander fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
What I was lost on earliest attempting to get started with react-native was understanding the host environment. It's not Node, it's not a browser, it appears to be a raw VM context, with a whole bunch of polyfills. When I tried to require Bluebird, I ran into errors, likely due to assumptions made about APIs provided by the host environment.
Also, it would be important to know how third-party libs can run tests in the same type of environment to fix these issues.
Thanks.
The text was updated successfully, but these errors were encountered: