8000 Doesn't work in browser environment · Issue #70 · ScottHamper/Cookies · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Doesn't work in browser environment #70

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
wzup opened this issue Jan 20, 2017 · 1 comment
Open

Doesn't work in browser environment #70

wzup opened this issue Jan 20, 2017 · 1 comment

Comments

@wzup
Copy link
wzup commented Jan 20, 2017

It doesn't work in browser environment. Or at least explain how to deploy it in a browser env. In your docs you write:
cookies-js - google chrome 2017-01-20 11 03 59

So it is pretty natural to assume that in a browser it should be the same, since you do not provide any other info about how to run it in a browser:

const Cookies = require('cookies-js')(window);
window.Cookies = Cookies;

But the result is

Cookies === undefined.

How does it work in a browser?

@ScottHamper
Copy link
Owner

Hey @wzup - you've highlighted another confusing aspect of the documentation that makes me feel rather silly, seeing it now!

Right now the export for Cookies.js is different depending on if you're in a browser environment that has a global window object, or not. This difference is something that has bothered me for a while and I'd like to change eventually. In a non-browser environment, it's necessary to pass in some object to act as the window object, since it doesn't exist. However, this requirement is unnecessary when in the browser.

As a result, if you're in a browser, and you're not using any script loader (you're not using AMD or CommonJS), then Cookies.js will create a global Cookies object ready to go (you can immediately start calling things like Cookies.get and Cookies.set).

If you are using a script loader, then simply requiring the library is enough to start using it. For example, for CommonJS, simply do:

var Cookies = require('cookies-js');

Apologies for the confusion! This is something I'd like to make more consistent in the future. In the mean time, I should absolutely update the readme with more helpful usage instructions.

Thanks for checking out the library!

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

No branches or pull requests

2 participants
0