ember-source 4.4.0-beta.1 → 4.5.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +1,88 @@
1
1
  /**
2
2
  @module @ember/engine
3
3
  */
4
- import { Object as EmberObject, ContainerProxyMixin, RegistryProxyMixin, RSVP } from '@ember/-internals/runtime';
4
+ import { Object as EmberObject, RSVP } from '@ember/-internals/runtime';
5
5
  import { assert } from '@ember/debug';
6
6
  import EmberError from '@ember/error';
7
7
  import { Registry, privatize as P } from '@ember/-internals/container';
8
8
  import { guidFor } from '@ember/-internals/utils';
9
9
  import { getEngineParent, setEngineParent } from './lib/engine-parent';
10
- /**
11
- The `EngineInstance` encapsulates all of the stateful aspects of a
12
- running `Engine`.
13
-
14
- @public
15
- @class EngineInstance
16
- @extends EmberObject
17
- @uses RegistryProxyMixin
18
- @uses ContainerProxyMixin
19
- */
20
-
21
- const EngineInstance = EmberObject.extend(RegistryProxyMixin, ContainerProxyMixin, {
10
+ import RegistryProxyMixin from '@ember/-internals/runtime/lib/mixins/registry_proxy';
11
+ import ContainerProxyMixin from '@ember/-internals/runtime/lib/mixins/container_proxy';
12
+ import { isFactory } from '@ember/-internals/owner';
13
+ import Engine from '.';
14
+ const CEngine = Engine;
15
+
16
+ class EngineInstance extends EmberObject.extend(RegistryProxyMixin, ContainerProxyMixin) {
17
+ constructor() {
18
+ super(...arguments);
19
+ this._booted = false;
20
+ this._bootPromise = null;
21
+ }
22
22
  /**
23
- The base `Engine` for which this is an instance.
24
- @property {Engine} engine
25
- @private
26
- */
27
- base: null,
23
+ @private
24
+ @method setupRegistry
25
+ @param {Registry} registry
26
+ @param {BootOptions} options
27
+ */
28
28
 
29
- init() {
30
- this._super(...arguments); // Ensure the guid gets setup for this instance
31
29
 
30
+ static setupRegistry(_registry, _options) {}
32
31
 
33
- guidFor(this);
34
- let base = this.base;
32
+ init(properties) {
33
+ var _a;
35
34
 
36
- if (!base) {
37
- base = this.application;
38
- this.base = base;
39
- } // Create a per-instance registry that will use the application's registry
40
- // as a fallback for resolving registrations.
35
+ super.init(properties); // Ensure the guid gets setup for this instance
41
36
 
37
+ guidFor(this);
38
+ (_a = this.base) !== null && _a !== void 0 ? _a : this.base = this.application; // Create a per-instance registry that will use the application's registry
39
+ // as a fallback for resolving registrations.
42
40
 
43
41
  let registry = this.__registry__ = new Registry({
44
- fallback: base.__registry__
42
+ fallback: this.base.__registry__
45
43
  }); // Create a per-instance container from the instance's registry
46
44
 
47
45
  this.__container__ = registry.container({
48
46
  owner: this
49
47
  });
50
48
  this._booted = false;
51
- },
52
-
49
+ }
53
50
  /**
54
51
  Initialize the `EngineInstance` and return a promise that resolves
55
52
  with the instance itself when the boot process is complete.
56
- The primary task here is to run any registered instance initializers.
57
- See the documentation on `BootOptions` for the options it takes.
58
- @public
53
+ The primary task here is to run any registered instance initializers.
54
+ See the documentation on `BootOptions` for the options it takes.
55
+ @public
59
56
  @method boot
60
57
  @param options {Object}
61
58
  @return {Promise<EngineInstance,Error>}
62
59
  */
60
+
61
+
63
62
  boot(options) {
64
63
  if (this._bootPromise) {
65
64
  return this._bootPromise;
66
65
  }
67
66
 
68
- this._bootPromise = new RSVP.Promise(resolve => resolve(this._bootSync(options)));
67
+ this._bootPromise = new RSVP.Promise(resolve => {
68
+ resolve(this._bootSync(options));
69
+ });
69
70
  return this._bootPromise;
70
- },
71
-
71
+ }
72
72
  /**
73
73
  Unfortunately, a lot of existing code assumes booting an instance is
74
74
  synchronous – specifically, a lot of tests assume the last call to
75
75
  `app.advanceReadiness()` or `app.reset()` will result in a new instance
76
76
  being fully-booted when the current runloop completes.
77
- We would like new code (like the `visit` API) to stop making this
77
+ We would like new code (like the `visit` API) to stop making this
78
78
  assumption, so we created the asynchronous version above that returns a
79
79
  promise. But until we have migrated all the code, we would have to expose
80
80
  this method for use *internally* in places where we need to boot an instance
81
81
  synchronously.
82
- @private
82
+ @private
83
83
  */
84
+
85
+
84
86
  _bootSync(options) {
85
87
  if (this._booted) {
86
88
  return this;
@@ -92,36 +94,39 @@ const EngineInstance = EmberObject.extend(RegistryProxyMixin, ContainerProxyMixi
92
94
  this.base.runInstanceInitializers(this);
93
95
  this._booted = true;
94
96
  return this;
95
- },
97
+ }
96
98
 
97
99
  setupRegistry(options = this.__container__.lookup('-environment:main')) {
98
100
  this.constructor.setupRegistry(this.__registry__, options);
99
- },
100
-
101
+ }
101
102
  /**
102
103
  Unregister a factory.
103
- Overrides `RegistryProxy#unregister` in order to clear any cached instances
104
+ Overrides `RegistryProxy#unregister` in order to clear any cached instances
104
105
  of the unregistered factory.
105
- @public
106
+ @public
106
107
  @method unregister
107
108
  @param {String} fullName
108
109
  */
110
+
111
+
109
112
  unregister(fullName) {
110
- this.__container__.reset(fullName);
113
+ this.__container__.reset(fullName); // We overwrote this method from RegistryProxyMixin.
111
114
 
112
- this._super(...arguments);
113
- },
114
115
 
116
+ this.__registry__.unregister(fullName);
117
+ }
115
118
  /**
116
119
  Build a new `EngineInstance` that's a child of this instance.
117
- Engines must be registered by name with their parent engine
120
+ Engines must be registered by name with their parent engine
118
121
  (or application).
119
- @private
122
+ @private
120
123
  @method buildChildEngineInstance
121
124
  @param name {String} the registered name of the engine.
122
125
  @param options {Object} options provided to the engine instance.
123
126
  @return {EngineInstance,Error}
124
127
  */
128
+
129
+
125
130
  buildChildEngineInstance(name, options = {}) {
126
131
  let Engine = this.lookup(`engine:${name}`);
127
132
 
@@ -129,49 +134,46 @@ const EngineInstance = EmberObject.extend(RegistryProxyMixin, ContainerProxyMixi
129
134
  throw new EmberError(`You attempted to mount the engine '${name}', but it is not registered with its parent.`);
130
135
  }
131
136
 
137
+ assert('expected an Engine', Engine instanceof CEngine);
132
138
  let engineInstance = Engine.buildInstance(options);
133
139
  setEngineParent(engineInstance, this);
134
140
  return engineInstance;
135
- },
136
-
141
+ }
137
142
  /**
138
143
  Clone dependencies shared between an engine instance and its parent.
139
- @private
144
+ @private
140
145
  @method cloneParentDependencies
141
146
  */
147
+
148
+
142
149
  cloneParentDependencies() {
143
- let parent = getEngineParent(this);
150
+ const parent = getEngineParent(this);
151
+ assert('expected parent', parent);
144
152
  let registrations = ['route:basic', 'service:-routing'];
145
- registrations.forEach(key => this.register(key, parent.resolveRegistration(key)));
153
+ registrations.forEach(key => {
154
+ let registration = parent.resolveRegistration(key);
155
+ assert('expected registration to be a factory', isFactory(registration));
156
+ this.register(key, registration);
157
+ });
146
158
  let env = parent.lookup('-environment:main');
147
159
  this.register('-environment:main', env, {
148
160
  instantiate: false
149
161
  });
150
162
  let singletons = ['router:main', P`-bucket-cache:main`, '-view-registry:main', `renderer:-dom`, 'service:-document'];
151
163
 
152
- if (env.isInteractive) {
164
+ if (env['isInteractive']) {
153
165
  singletons.push('event_dispatcher:main');
154
166
  }
155
167
 
156
- singletons.forEach(key => this.register(key, parent.lookup(key), {
157
- instantiate: false
158
- }));
168
+ singletons.forEach(key => {
169
+ // SAFETY: We already expect this to be a singleton
170
+ let singleton = parent.lookup(key);
171
+ this.register(key, singleton, {
172
+ instantiate: false
173
+ });
174
+ });
159
175
  }
160
176
 
161
- });
162
- EngineInstance.reopenClass({
163
- /**
164
- @private
165
- @method setupRegistry
166
- @param {Registry} registry
167
- @param {BootOptions} options
168
- */
169
- setupRegistry(registry, options) {
170
- // when no options/environment is present, do nothing
171
- if (!options) {
172
- return;
173
- }
174
- }
177
+ }
175
178
 
176
- });
177
179
  export default EngineInstance;
@@ -1 +1 @@
1
- export default "4.4.0-beta.1";
1
+ export default "4.5.0-alpha.1";