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

[FEATURE ember-application-engines] Initial extraction of engines from applications #12685

Merged
merged 10 commits into from Dec 8, 2015
Merged
3 changes: 2 additions & 1 deletion features.json
Expand Up @@ -10,6 +10,7 @@
"ember-metal-ember-assign": null,
"ember-contextual-components": true,
"ember-container-inject-owner": true,
"ember-htmlbars-local-lookup": null
"ember-htmlbars-local-lookup": null,
"ember-application-engines": null
}
}
12 changes: 12 additions & 0 deletions packages/ember-application/lib/index.js
@@ -1,4 +1,5 @@
import Ember from 'ember-metal/core';
import isEnabled from 'ember-metal/features';
import { runLoadHooks } from 'ember-runtime/system/lazy_load';

/**
Expand All @@ -11,10 +12,21 @@ import {
Resolver
} from 'ember-application/system/resolver';
import Application from 'ember-application/system/application';
import ApplicationInstance from 'ember-application/system/application-instance';
import Engine from 'ember-application/system/engine';
import EngineInstance from 'ember-application/system/engine-instance';

Ember.Application = Application;
Ember.Resolver = Resolver;
Ember.DefaultResolver = 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;
}

runLoadHooks('Ember.Application', Application);
47 changes: 5 additions & 42 deletions packages/ember-application/lib/system/application-instance.js
Expand Up @@ -7,18 +7,16 @@ import { deprecate } from 'ember-metal/debug';
import isEnabled from 'ember-metal/features';
import { get } from 'ember-metal/property_get';
import { set } from 'ember-metal/property_set';
import EmberObject from 'ember-runtime/system/object';
import run from 'ember-metal/run_loop';
import { computed } from 'ember-metal/computed';
import ContainerProxy from 'ember-runtime/mixins/container_proxy';
import DOMHelper from 'ember-htmlbars/system/dom-helper';
import Registry from 'container/registry';
import RegistryProxy, { buildFakeRegistryWithDeprecations } from 'ember-runtime/mixins/registry_proxy';
import { buildFakeRegistryWithDeprecations } from 'ember-runtime/mixins/registry_proxy';
import Renderer from 'ember-metal-views/renderer';
import assign from 'ember-metal/assign';
import environment from 'ember-metal/environment';
import RSVP from 'ember-runtime/ext/rsvp';
import jQuery from 'ember-views/system/jquery';
import EngineInstance from './engine-instance';


let BootOptions;
Expand All @@ -45,12 +43,10 @@ let BootOptions;

@public
@class Ember.ApplicationInstance
@extends Ember.Object
@uses RegistryProxyMixin
@uses ContainerProxyMixin
@extends Ember.EngineInstance
*/

let ApplicationInstance = EmberObject.extend(RegistryProxy, ContainerProxy, {
const ApplicationInstance = EngineInstance.extend({
/**
The `Application` for which this is an instance.

Expand Down Expand Up @@ -85,22 +81,12 @@ let ApplicationInstance = EmberObject.extend(RegistryProxy, ContainerProxy, {
init() {
this._super(...arguments);

var application = get(this, 'application');
let application = this.application;

if (!isEnabled('ember-application-visit')) {
set(this, 'rootElement', get(application, 'rootElement'));
}

// Create a per-instance registry that will use the application's registry
// as a fallback for resolving registrations.
var applicationRegistry = get(application, '__registry__');
var registry = this.__registry__ = new Registry({
fallback: applicationRegistry
});

// Create a per-instance container from the instance's registry
this.__container__ = registry.container({ owner: this });

// Register this instance in the per-instance registry.
//
// Why do we need to register the instance in the first place?
Expand Down Expand Up @@ -270,29 +256,6 @@ let ApplicationInstance = EmberObject.extend(RegistryProxy, ContainerProxy, {
dispatcher.setup(customEvents, this.rootElement);

return dispatcher;
},

/**
@private
*/
willDestroy() {
this._super(...arguments);
run(this.__container__, 'destroy');
},

/**
Unregister a factory.

Overrides `RegistryProxy#unregister` in order to clear any cached instances
of the unregistered factory.

@public
@method unregister
@param {String} fullName
*/
unregister(fullName) {
this.__container__.reset(fullName);
this._super(...arguments);
}
});

Expand Down