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

Remove ember-application-engines feature flag. #14199

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"features-stripped-test": null,
"ember-routing-route-configured-query-params": null,
"ember-libraries-isregistered": null,
"ember-application-engines": true,
"ember-runtime-computed-uniq-by": true,
"ember-improved-instrumentation": null,
"ember-runtime-enumerable-includes": true,
Expand Down
13 changes: 3 additions & 10 deletions packages/ember-application/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Ember from 'ember-metal/core'; // reexports
import isEnabled from 'ember-metal/features';
import { runLoadHooks } from 'ember-runtime/system/lazy_load';

/**
Expand All @@ -17,17 +16,11 @@ import Engine from './system/engine';
import EngineInstance from './system/engine-instance';

Ember.Application = Application;
Ember.ApplicationInstance = ApplicationInstance;
Ember.Engine = Engine;
Ember.EngineInstance = EngineInstance;
Ember.DefaultResolver = Ember.Resolver = DefaultResolver;

if (isEnabled('ember-application-engines')) {
Ember.Engine = Engine;

// Expose `EngineInstance` and `ApplicationInstance` for easy overriding.
// Reanalyze whether to continue exposing these after feature flag is removed.
Ember.EngineInstance = EngineInstance;
Ember.ApplicationInstance = ApplicationInstance;
}

// add domTemplates initializer (only does something if `ember-template-compiler`
// is loaded already)
import './initializers/dom-templates';
Expand Down
130 changes: 61 additions & 69 deletions packages/ember-application/lib/system/engine-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { assert } from 'ember-metal/debug';
import run from 'ember-metal/run_loop';
import RSVP from 'ember-runtime/ext/rsvp';
import { guidFor } from 'ember-metal/utils';
import isEnabled from 'ember-metal/features';

/**
The `EngineInstance` encapsulates all of the stateful aspects of a
Expand All @@ -25,7 +24,6 @@ import isEnabled from 'ember-metal/features';
@extends Ember.Object
@uses RegistryProxyMixin
@uses ContainerProxyMixin
@category ember-application-engines
*/

const EngineInstance = EmberObject.extend(RegistryProxy, ContainerProxy, {
Expand Down Expand Up @@ -101,9 +99,7 @@ const EngineInstance = EmberObject.extend(RegistryProxy, ContainerProxy, {

assert('An engine instance\'s parent must be set via `setEngineParent(engine, parent)` prior to calling `engine.boot()`.', getEngineParent(this));

if (isEnabled('ember-application-engines')) {
this.cloneParentDependencies();
}
this.cloneParentDependencies();

this.setupRegistry(options);

Expand Down Expand Up @@ -139,6 +135,66 @@ const EngineInstance = EmberObject.extend(RegistryProxy, ContainerProxy, {
willDestroy() {
this._super(...arguments);
run(this.__container__, 'destroy');
},

/**
Build a new `Ember.EngineInstance` that's a child of this instance.

Engines must be registered by name with their parent engine
(or application).

@private
@method buildChildEngineInstance
@param name {String} the registered name of the engine.
@param options {Object} options provided to the engine instance.
@return {Ember.EngineInstance,Error}
*/
buildChildEngineInstance(name, options = {}) {
let Engine = this.lookup(`engine:${name}`);

if (!Engine) {
throw new EmberError(`You attempted to mount the engine '${name}', but it is not registered with its parent.`);
}

let engineInstance = Engine.buildInstance(options);

setEngineParent(engineInstance, this);

return engineInstance;
},

/**
Clone dependencies shared between an engine instance and its parent.

@private
@method cloneParentDependencies
*/
cloneParentDependencies() {
let parent = getEngineParent(this);

let registrations = [
'route:basic',
'event_dispatcher:main',
'service:-routing',
'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',
`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 Expand Up @@ -166,68 +222,4 @@ EngineInstance.reopenClass({
}
});

if (isEnabled('ember-application-engines')) {
EngineInstance.reopen({
/**
Build a new `Ember.EngineInstance` that's a child of this instance.

Engines must be registered by name with their parent engine
(or application).

@private
@method buildChildEngineInstance
@param name {String} the registered name of the engine.
@param options {Object} options provided to the engine instance.
@return {Ember.EngineInstance,Error}
*/
buildChildEngineInstance(name, options = {}) {
let Engine = this.lookup(`engine:${name}`);

if (!Engine) {
throw new EmberError(`You attempted to mount the engine '${name}', but it is not registered with its parent.`);
}

let engineInstance = Engine.buildInstance(options);

setEngineParent(engineInstance, this);

return engineInstance;
},

/**
Clone dependencies shared between an engine instance and its parent.

@private
@method cloneParentDependencies
*/
cloneParentDependencies() {
let parent = getEngineParent(this);

let registrations = [
'route:basic',
'event_dispatcher:main',
'service:-routing',
'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',
`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');
}
});
}

export default EngineInstance;
1 change: 0 additions & 1 deletion packages/ember-application/lib/system/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function props(obj) {
@namespace Ember
@extends Ember.Namespace
@uses RegistryProxy
@category ember-application-engines
@public
*/
const Engine = Namespace.extend(RegistryProxy, {
Expand Down
107 changes: 52 additions & 55 deletions packages/ember-application/tests/system/application_instance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import ApplicationInstance from 'ember-application/system/application-instance';
import run from 'ember-metal/run_loop';
import jQuery from 'ember-views/system/jquery';
import factory from 'container/tests/test-helpers/factory';
import isEnabled from 'ember-metal/features';
import { privatize as P } from 'container';
import EmberObject from 'ember-runtime/system/object';

Expand Down Expand Up @@ -139,67 +138,65 @@ QUnit.test('unregistering a factory clears all cached instances of that factory'
assert.notStrictEqual(postController1, postController2, 'lookup creates a brand new instance, because the previous one was reset');
});

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

let ChatEngine = Engine.extend();
let chatEngineInstance;
let ChatEngine = Engine.extend();
let chatEngineInstance;

application.register('engine:chat', ChatEngine);
application.register('engine:chat', ChatEngine);

run(() => {
appInstance = ApplicationInstance.create({ application });
appInstance.setupRegistry();
chatEngineInstance = appInstance.buildChildEngineInstance('chat');
});
run(() => {
appInstance = ApplicationInstance.create({ application });
appInstance.setupRegistry();
chatEngineInstance = appInstance.buildChildEngineInstance('chat');
});

return chatEngineInstance.boot()
.then(() => {
assert.ok(true, 'boot successful');

let registrations = [
'route:basic',
'event_dispatcher:main',
'service:-routing',
'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'
];

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),
`Engine and parent app share singleton '${key}'`);
});
return chatEngineInstance.boot()
.then(() => {
assert.ok(true, 'boot successful');

let registrations = [
'route:basic',
'event_dispatcher:main',
'service:-routing',
'service:-glimmer-environment'
];

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

QUnit.test('can build a registry via Ember.ApplicationInstance.setupRegistry() -- simulates ember-test-helpers', function(assert) {
let namespace = EmberObject.create({
Resolver: { create: function() { } }
let singletons = [
'router:main',
P`-bucket-cache:main`,
'-view-registry:main',
'-environment:main'
];

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),
`Engine and parent app share singleton '${key}'`);
});
});
});

let registry = Application.buildRegistry(namespace);
QUnit.test('can build a registry via Ember.ApplicationInstance.setupRegistry() -- simulates ember-test-helpers', function(assert) {
let namespace = EmberObject.create({
Resolver: { create: function() { } }
});

ApplicationInstance.setupRegistry(registry);
let registry = Application.buildRegistry(namespace);

assert.equal(registry.resolve('service:-document'), document);
});
}
ApplicationInstance.setupRegistry(registry);

assert.equal(registry.resolve('service:-document'), document);
});
Loading