Skip to content

Commit

Permalink
[BUGFIX beta] Clone additional parent dependencies into engine instan…
Browse files Browse the repository at this point in the history
…ces.

An engine instance needs to share the following with its parent:

* `service:-glimmer-environment` (only for glimmer)
* `renderer:-dom` or `renderer:-inert`, depending on whether the environment
  is interactive
  • Loading branch information
dgeb authored and Robert Jackson committed Aug 26, 2016
1 parent b769492 commit 79026a7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ BootOptions.prototype.toEnvironment = function() {
let env = assign({}, environment);
// For compatibility with existing code
env.hasDOM = this.isBrowser;
env.isInteractive = this.isInteractive;
env.options = this;
return env;
};
Expand Down
21 changes: 16 additions & 5 deletions packages/ember-application/lib/system/engine-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,29 @@ if (isEnabled('ember-application-engines')) {
cloneParentDependencies() {
let parent = getEngineParent(this);

[
let registrations = [
'route:basic',
'event_dispatcher:main',
'service:-routing'
].forEach(key => this.register(key, parent.resolveRegistration(key)));
];

[
if (isEnabled('ember-glimmer')) {
registrations.push('service:-glimmer-environment');
}

registrations.forEach(key => this.register(key, parent.resolveRegistration(key)));

let env = parent.lookup('-environment:main');
this.register('-environment:main', env, { instantiate: false });

let singletons = [
'router:main',
P`-bucket-cache:main`,
'-view-registry:main',
'-environment:main'
].forEach(key => this.register(key, parent.lookup(key), { instantiate: false }));
`renderer:-${env.isInteractive ? 'dom' : 'inert'}`
];

singletons.forEach(key => this.register(key, parent.lookup(key), { instantiate: false }));

this.inject('view', '_environment', '-environment:main');
this.inject('route', '_environment', '-environment:main');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ QUnit.test('unregistering a factory clears all cached instances of that factory'

if (isEnabled('ember-application-engines')) {
QUnit.test('can build and boot a registered engine', function(assert) {
assert.expect(8);
assert.expect(isEnabled('ember-glimmer') ? 10 : 9);

let ChatEngine = Engine.extend();
let chatEngineInstance;
Expand All @@ -158,23 +158,34 @@ if (isEnabled('ember-application-engines')) {
.then(() => {
assert.ok(true, 'boot successful');

[
let registrations = [
'route:basic',
'event_dispatcher:main',
'service:-routing'
].forEach(key => {
];

if (isEnabled('ember-glimmer')) {
registrations.push('service:-glimmer-environment');
}

registrations.forEach(key => {
assert.strictEqual(
chatEngineInstance.resolveRegistration(key),
appInstance.resolveRegistration(key),
`Engine and parent app share registrations for '${key}'`);
});

[
let singletons = [
'router:main',
P`-bucket-cache:main`,
'-view-registry:main',
'-environment:main'
].forEach(key => {
];

let env = appInstance.lookup('-environment:main');
singletons.push(env.isInteractive ? 'renderer:-dom' : 'renderer:-inert');

singletons.forEach(key => {
assert.strictEqual(
chatEngineInstance.lookup(key),
appInstance.lookup(key),
Expand Down

0 comments on commit 79026a7

Please sign in to comment.