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

Different environment instances share globals #573

Closed
thepechinator opened this issue Oct 30, 2015 · 6 comments
Closed

Different environment instances share globals #573

thepechinator opened this issue Oct 30, 2015 · 6 comments

Comments

@thepechinator
Copy link
Contributor

Wanted to see if this was intended behavior. When I call nunjucks.configure multiple times and get different Environment instances: if I add a global to the first instance, it will also be tied to any other instance that is created afterwards.

Example:

var env = nunjucks.configure();
env.addGlobal('test', 'value');

// Looking at the code, this should return a new instance of Environment
var env2 = nunjucks.configure();
// will return 'value' when I was expecting it to say 'global not found'
env2.getGlobal('test');

Most people will probably only need one Environment in most cases, but this is something I didn't realize until I ran into it. Also, kind of related and out of curiosity, is there a good reason there's no removeGlobal or removeFilter method? Thanks!

@rhengles
Copy link
Contributor

Is the last line a typo? You're reading from the same env where you called addGlobal.

@thepechinator
Copy link
Contributor Author

Oh yeah, good catch. Thanks, I edited it.

@carljm
Copy link
Contributor

carljm commented Oct 30, 2015

I don't have time to look into this and verify it at the moment, but if in fact this is the behavior, IMO it is clearly a bug and should be fixed. Environments should be independent.

Also I have no problem with adding removeFilter and removeGlobal, just nobody has bothered to do so yet. That should be opened as a separate issue (or just a PR).

@devoidfury
Copy link
Contributor

Just confirming, globals are global to nunjucks -- it's essentially just the exports object from src/globals.js

@thepechinator
Copy link
Contributor Author

Thanks for the quick response. I went ahead and made a PR for the globals.

@carljm
Copy link
Contributor

carljm commented Dec 14, 2015

Fixed with merge of #574.

@carljm carljm closed this as completed Dec 14, 2015
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

No branches or pull requests

4 participants