Skip to content

Commit

Permalink
Merge pull request #12685 from dgeb/engines
Browse files Browse the repository at this point in the history
[FEATURE ember-application-engines] Initial extraction of engines from applications
  • Loading branch information
rwjblue committed Dec 8, 2015
2 parents 3561214 + 18b0a61 commit 192fceb
Show file tree
Hide file tree
Showing 9 changed files with 622 additions and 402 deletions.
3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 192fceb

Please sign in to comment.