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

benv.teardown(false) is default #19

Closed
craigspaeth opened this issue Apr 15, 2015 · 1 comment
Closed

benv.teardown(false) is default #19

craigspaeth opened this issue Apr 15, 2015 · 1 comment

Comments

@craigspaeth
Copy link
Contributor

Too many libraries caching references to DOM globals... probably best to make this default.

@craigspaeth
Copy link
Contributor Author

Just to note why this is the more pragmatic solution...

The issue here is libraries that cache references to DOM globals. e.g. something that looks like this:

var w = window;
w.$ = w.Zepto = function(){}

Then let's say we have a view:

var $ = require('zepto');
var MyView = function() {
  $('.el').html('foo')
}

This means through the lifecycle of the process w in Zepto will refer to a local copy of that instance of window. This is problematic when using benv.teardown(true) b/c it will delete the global instances of window and the next benv.setup will create a new window + DOM environment. Meanwhile our view is still holding on to a cached require('zepto') which is holding on to that old instance of window in w.

There are two options to solve this problem 1. Be diligent in setting up and tearing down a clean DOM by clearing out require caches until the code is always re-setting var w = window 2. Let benv hold on to one instance of the DOM per process and let the programmer deal with setup/teardown of mutating global DOM state. We are choosing the latter because the former has proven even more tedious of a black box to understand (e.g. when to require/rewire/clear cached modules/etc.) whereas the latter is more obvious and closer to what one would be dealing with in typical browser testing.

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

1 participant