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

[JS] Expose global as `self` too #1419

Closed
johanneslumpe opened this Issue May 27, 2015 · 10 comments

Comments

Projects
None yet
6 participants
@johanneslumpe
Contributor

johanneslumpe commented May 27, 2015

In JavascriptCore self is not defined. Libraries like bluebird for example rely on self being the global object instead of window, as it works in web workers too.

This fails in react-native due to self not being defined. A simple global.self = global at the beginning of the script solves this issue. Could we get this into the default packaged code so that we don't have to put the statement in there by ourselves?

Edit: As discussed in petkaantonov/bluebird#630

@jtremback

This comment has been minimized.

Show comment
Hide comment
@jtremback

jtremback May 28, 2015

Contributor

Sounds pretty drastic to be defining new top-level variables to support some library!

Contributor

jtremback commented May 28, 2015

Sounds pretty drastic to be defining new top-level variables to support some library!

@johanneslumpe

This comment has been minimized.

Show comment
Hide comment
@johanneslumpe

johanneslumpe May 28, 2015

Contributor

Except for the fact that it's available in every browser and web workers - it's more of a generic fix for the runtime which is missing a prop on the window object than just "supporting some library". Read about it here: https://developer.mozilla.org/en-US/docs/Web/API/Window/self

Sent from my iPhone

On 28 May 2015, at 21:08, Jehan notifications@github.com wrote:

Sounds pretty drastic to be defining new top-level variables to support some library!


Reply to this email directly or view it on GitHub.

Contributor

johanneslumpe commented May 28, 2015

Except for the fact that it's available in every browser and web workers - it's more of a generic fix for the runtime which is missing a prop on the window object than just "supporting some library". Read about it here: https://developer.mozilla.org/en-US/docs/Web/API/Window/self

Sent from my iPhone

On 28 May 2015, at 21:08, Jehan notifications@github.com wrote:

Sounds pretty drastic to be defining new top-level variables to support some library!


Reply to this email directly or view it on GitHub.

@brentvatne

This comment has been minimized.

Show comment
Hide comment
@brentvatne

brentvatne May 28, 2015

Collaborator

@johanneslumpe - good point, what do you think @vjeux?

Collaborator

brentvatne commented May 28, 2015

@johanneslumpe - good point, what do you think @vjeux?

@brentvatne brentvatne changed the title from Expose global as `self` too to [JS] Expose global as `self` too May 28, 2015

@vjeux

This comment has been minimized.

Show comment
Hide comment
@vjeux

vjeux May 28, 2015

Contributor

Finding the global object is annoying as there is no standard way of doing it. Here are 4 ways and how they behave:

>> node
> self
ReferenceError: self is not defined
> window
ReferenceError: window is not defined
> this
{...}
> global
{...}
// browser
> self
{...}
> window
{...}
> this
{...}
> global
Uncaught ReferenceError: global is not defined

this has the best coverage.

As to introduce self in react-native, I'm unsure. I'd really like to avoid adding 10 different ways to do the same thing. I'd love to find a way to get one solution that works everywhere and implement this one

Contributor

vjeux commented May 28, 2015

Finding the global object is annoying as there is no standard way of doing it. Here are 4 ways and how they behave:

>> node
> self
ReferenceError: self is not defined
> window
ReferenceError: window is not defined
> this
{...}
> global
{...}
// browser
> self
{...}
> window
{...}
> this
{...}
> global
Uncaught ReferenceError: global is not defined

this has the best coverage.

As to introduce self in react-native, I'm unsure. I'd really like to avoid adding 10 different ways to do the same thing. I'd love to find a way to get one solution that works everywhere and implement this one

@ide

This comment has been minimized.

Show comment
Hide comment
@ide

ide May 28, 2015

Collaborator

Seems like this is the kind of thing that could be neatly maintained by a standalone project for the most part. Ex: npm install react-native-browser-polyfill + import 'react-native-browser-polyfill and have docs that explain this. Then if it turns out that basically everyone ends up doing this, it'd be pretty easy to include it with the default react environment.

Collaborator

ide commented May 28, 2015

Seems like this is the kind of thing that could be neatly maintained by a standalone project for the most part. Ex: npm install react-native-browser-polyfill + import 'react-native-browser-polyfill and have docs that explain this. Then if it turns out that basically everyone ends up doing this, it'd be pretty easy to include it with the default react environment.

@brentvatne

This comment has been minimized.

Show comment
Hide comment
@brentvatne

brentvatne May 28, 2015

Collaborator

@johanneslumpe - want to make that module? 😄 Thanks @vjeux & @ide

Collaborator

brentvatne commented May 28, 2015

@johanneslumpe - want to make that module? 😄 Thanks @vjeux & @ide

@johanneslumpe

This comment has been minimized.

Show comment
Hide comment
@johanneslumpe

johanneslumpe May 29, 2015

Contributor

@brentvatne @ide @vjeux Yeah I think I can cook up that module. Will probably use the name @ide suggested. And it will only contain a single polyfill for now, but maybe we can add more in the future.

Contributor

johanneslumpe commented May 29, 2015

@brentvatne @ide @vjeux Yeah I think I can cook up that module. Will probably use the name @ide suggested. And it will only contain a single polyfill for now, but maybe we can add more in the future.

@ide

This comment has been minimized.

Show comment
Hide comment
@ide

ide May 29, 2015

Collaborator

Sounds like a plan.

Collaborator

ide commented May 29, 2015

Sounds like a plan.

@ide ide closed this May 29, 2015

@johanneslumpe

This comment has been minimized.

Show comment
Hide comment
@johanneslumpe

johanneslumpe May 30, 2015

Contributor

Published as react-native-browser-polyfill!

Contributor

johanneslumpe commented May 30, 2015

Published as react-native-browser-polyfill!

@ide

This comment has been minimized.

Show comment
Hide comment
Collaborator

ide commented May 30, 2015

@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.