Skip to content

Support running inside a Web Worker #60

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ariofrio
Copy link

@ariofrio ariofrio commented Mar 3, 2012

Support running from loadScript() inside a Web Worker (there is no window nor document there), in Chrome.

@@ -12,7 +12,7 @@
, attachEvent = 'attachEvent'
, removeEvent = 'removeEventListener'
, detachEvent = 'detachEvent'
, doc = document || {}
, doc = typeof document !== 'undefined' ? document : {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

does document || {} not do the right thing in a worker?

Copy link
Author

Choose a reason for hiding this comment

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

no. try doing a = thisvardoesnotexist || {}; in the Chrome Javascript console :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh ya, of course.

@rvagg
Copy link
Collaborator

rvagg commented Mar 4, 2012

Interesting use case. I'm wondering how you're using Bean in a WebWorker? Are you listening to browser events or using it for pubsub? If the aim of this PR is to add WW support perhaps some tests for that would be neat if you can manage it.

@kkaefer
Copy link

kkaefer commented Nov 18, 2013

I'd like to extend this request to node.js; bean.js assumes some global objects like window, document or navigator which do not exist in node land.

@ryanve
Copy link

ryanve commented Nov 18, 2013

It makes sense to include the checks. false could suffice if no in tests are needed:

var doc = typeof document !== 'undefined' && document

@rvagg
Copy link
Collaborator

rvagg commented Nov 19, 2013

I'd like to see some tests for some of this, anyone got time and ideas for testing in webworkers and/or testing in node?

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.

4 participants