-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Don’t share view registry across containers #10599
Conversation
Previously, all rendered views were inserted into the Ember.View.views global hash, indexed by their `elementId`. This hash is used by the EventDispatcher to locate views, and is also used by some advanced developers as a debugging aid. Unfortunately, using a global shared store of views is problematic in the FastBoot/application instance case, since multiple views with the same elementId can exist at the same time. This creates a race condition where the second view to be created will throw an exception, as Ember believes that a view with that element ID has already been created (normally an error in “single app” mode). This commit introduces the notion of a “view registry”, which is just a simple hash injected onto views and shared container-wide. Because each application instance in FastBoot has its own container, these views will naturally be isolated. To preserve backwards-compatibility, the default instance created when the app is booting normally (i.e., autoboot is `false`) injects the global Ember.View.views hash. We should consider removing this entirely in Ember 2.0, now that the Container pane of the Inspector gives developers easier access to registered views. Do note, however, that the Event Dispatcher still has a dependency on the global Ember.View.views, though it could be relatively easily refactored to also have the view registry injected.
@@ -21,8 +21,8 @@ merge(inDOM, { | |||
// Register the view for event handling. This hash is used by | |||
// Ember.EventDispatcher to dispatch incoming events. | |||
if (!view.isVirtual) { | |||
Ember.assert("Attempted to register a view with an id already in use: "+view.elementId, !View.views[view.elementId]); | |||
View.views[view.elementId] = view; | |||
Ember.assert("Attempted to register a view with an id already in use: "+view.elementId, !view._viewRegistry[view.elementId]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would probably want to move these asserts to the _register function
@igorT I've updated the PR to incorporate your suggestions, thank you! |
💯 |
Don’t share view registry across containers
@tomdale we should inject the view registry on the event dispatcher both of which should be in the container for 2.0 |
@krisselden Yep, planning that for a future refactor. |
Previously, all rendered views were inserted into the Ember.View.views global hash, indexed by their
elementId
. This hash is used by the EventDispatcher to locate views, and is also used by some advanced developers as a debugging aid.Unfortunately, using a global shared store of views is problematic in the FastBoot/application instance case, since multiple views with the same elementId can exist at the same time. This creates a race condition where the second view to be created will throw an exception, as Ember believes that a view with that element ID has already been created (normally an error in “single app” mode).
This commit introduces the notion of a “view registry”, which is just a simple hash injected onto views and shared container-wide. Because each application instance in FastBoot has its own container, these views will naturally be isolated.
To preserve backwards-compatibility, the default instance created when the app is booting normally (i.e., autoboot is
false
) injects the global Ember.View.views hash. We should consider removing this entirely in Ember 2.0, now that the Container pane of the Inspector gives developers easier access to registered views. Do note, however, that the Event Dispatcher still has a dependency on the global Ember.View.views, though it could be relatively easily refactored to also have the view registry injected.