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

Don’t share view registry across containers #10599

Merged
merged 3 commits into from
Mar 10, 2015
Merged

Don’t share view registry across containers #10599

merged 3 commits into from
Mar 10, 2015

Conversation

tomdale
Copy link
Member

@tomdale tomdale commented Mar 10, 2015

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.

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]);
Copy link
Member

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

@tomdale
Copy link
Member Author

tomdale commented Mar 10, 2015

@igorT I've updated the PR to incorporate your suggestions, thank you!

@mixonic
Copy link
Sponsor Member

mixonic commented Mar 10, 2015

💯

mixonic added a commit that referenced this pull request Mar 10, 2015
Don’t share view registry across containers
@mixonic mixonic merged commit 069a243 into master Mar 10, 2015
@mixonic mixonic deleted the view-registry branch March 10, 2015 18:17
@krisselden
Copy link
Contributor

@tomdale we should inject the view registry on the event dispatcher both of which should be in the container for 2.0

@tomdale
Copy link
Member Author

tomdale commented Mar 11, 2015

@krisselden Yep, planning that for a future refactor.

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.

6 participants