Skip to content

Commit

Permalink
Merge pull request #11270 from rwjblue/ensure-view-registry-is-passed…
Browse files Browse the repository at this point in the history
…-down

[BUGFIX beta] Ensure view registry is provided to components.
  • Loading branch information
rwjblue committed May 25, 2015
2 parents 4218f01 + 41b4968 commit 1d91c95
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ export function createComponent(_component, isAngleBracket, _props, renderNode,
}

props.renderer = props.parentView ? props.parentView.renderer : env.container.lookup('renderer:-dom');
props._viewRegistry = props.parentView ? props.parentView._viewRegistry : props.container && props.container.lookup('-view-registry:main');

let component = _component.create(props);

// for the fallback case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export function createOrUpdateComponent(component, options, createOptions, rende
mergeBindings(props, shadowedAttrs(proto, snapshot));
props.container = options.parentView ? options.parentView.container : env.container;
props.renderer = options.parentView ? options.parentView.renderer : props.container && props.container.lookup('renderer:-dom');
props._viewRegistry = options.parentView ? options.parentView._viewRegistry : props.container && props.container.lookup('-view-registry:main');

if (proto.controller !== defaultController || hasSuppliedController) {
delete props._context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,47 @@ QUnit.test("components in template of a yielding component should have the prope
equal(outer.parentView, view, 'x-outer receives the ambient scope as its parentView');
});

QUnit.test("components should receive the viewRegistry from the parent view", function() {
var outer, innerTemplate, innerLayout;

var viewRegistry = {};

registry.register('component:x-outer', Component.extend({
init() {
this._super(...arguments);
outer = this;
}
}));

registry.register('component:x-inner-in-template', Component.extend({
init() {
this._super(...arguments);
innerTemplate = this;
}
}));

registry.register('component:x-inner-in-layout', Component.extend({
init() {
this._super(...arguments);
innerLayout = this;
}
}));

registry.register('template:components/x-outer', compile('{{x-inner-in-layout}}{{yield}}'));

view = EmberView.extend({
_viewRegistry: viewRegistry,
template: compile('{{#x-outer}}{{x-inner-in-template}}{{/x-outer}}'),
container: container
}).create();

runAppend(view);

equal(innerTemplate._viewRegistry, viewRegistry);
equal(innerLayout._viewRegistry, viewRegistry);
equal(outer._viewRegistry, viewRegistry);
});

QUnit.test("comopnent should rerender when a property (with a default) is changed during children's rendering", function() {
expectDeprecation(/modified value twice in a single render/);

Expand Down

0 comments on commit 1d91c95

Please sign in to comment.