Add Ember Application/Engine#buildInstance()

This commit is contained in:
James C. Davis
2018-08-14 09:40:46 -04:00
parent 83b529136c
commit d268ced4d3
4 changed files with 56 additions and 0 deletions

View File

@@ -496,6 +496,10 @@ declare module 'ember' {
* object when the boot process is complete.
*/
boot(): Promise<Application>;
/**
* Create an ApplicationInstance for this Application.
*/
buildInstance(options?: object): ApplicationInstance;
}
/**
The `ApplicationInstance` encapsulates all of the stateful aspects of a
@@ -1113,6 +1117,10 @@ declare module 'ember' {
* Set this to provide an alternate class to `Ember.DefaultResolver`
*/
resolver: Resolver;
/**
* Create an EngineInstance for this Engine.
*/
buildInstance(options?: object): EngineInstance;
}
/**
* The `EngineInstance` encapsulates all of the stateful aspects of a

View File

@@ -33,3 +33,9 @@ let App2 = BaseApp.create({
mouseleave: null
}
});
let App3 = BaseApp.create();
let App3Instance1 = App3.buildInstance();
let App3Instance2 = App3.buildInstance({ foo: 'bar' });

41
types/ember/test/engine.ts Executable file
View File

@@ -0,0 +1,41 @@
import Ember from 'ember';
import { assertType } from "./lib/assert";
let BaseEngine = Ember.Engine.extend({
modulePrefix: 'my-engine'
});
BaseEngine.initializer({
name: 'my-initializer',
initialize(engine) {
engine.register('foo:bar', Ember.Object.extend({ foo: 'bar' }));
}
});
BaseEngine.instanceInitializer({
name: 'my-instance-initializer',
initialize(engine) {
engine.lookup('foo:bar').get('foo');
}
});
let Engine1 = BaseEngine.create({
rootElement: '#engine-one',
customEvents: {
paste: 'paste'
}
});
let Engine2 = BaseEngine.create({
rootElement: '#engine-two',
customEvents: {
mouseenter: null,
mouseleave: null
}
});
let Engine3 = BaseEngine.create();
let Engine3Instance1 = Engine3.buildInstance();
let Engine3Instance2 = Engine3.buildInstance({ foo: 'bar' });

View File

@@ -24,6 +24,7 @@
"test/application.ts",
"test/access-modifier.ts",
"test/application-instance.ts",
"test/engine.ts",
"test/engine-instance.ts",
"test/ember-tests.ts",
"test/error.ts",