ember-source 5.11.0 → 5.11.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.
Files changed (147) hide show
  1. package/build-metadata.json +3 -3
  2. package/dist/ember-template-compiler.js +48 -42
  3. package/dist/ember-testing.js +1 -1
  4. package/dist/ember.debug.js +23102 -23100
  5. package/dist/ember.prod.js +31562 -31563
  6. package/dist/packages/@ember/-internals/container/index.js +1 -1
  7. package/dist/packages/@ember/-internals/deprecations/index.js +2 -1
  8. package/dist/packages/@ember/-internals/glimmer/index.js +2 -1
  9. package/dist/packages/@ember/-internals/meta/lib/meta.js +4 -3
  10. package/dist/packages/@ember/-internals/metal/index.js +9 -8
  11. package/dist/packages/@ember/-internals/routing/index.js +6 -5
  12. package/dist/packages/@ember/-internals/runtime/lib/ext/rsvp.js +3 -2
  13. package/dist/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +6 -5
  14. package/dist/packages/@ember/-internals/runtime/lib/mixins/action_handler.js +4 -3
  15. package/dist/packages/@ember/-internals/runtime/lib/mixins/container_proxy.js +1 -1
  16. package/dist/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js +2 -1
  17. package/dist/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +4 -3
  18. package/dist/packages/@ember/-internals/string/index.js +1 -1
  19. package/dist/packages/@ember/-internals/utils/index.js +4 -4
  20. package/dist/packages/@ember/-internals/views/index.js +1 -1
  21. package/dist/packages/@ember/-internals/views/lib/compat/fallback-view-registry.js +1 -1
  22. package/dist/packages/@ember/-internals/views/lib/component_lookup.js +1 -1
  23. package/dist/packages/@ember/-internals/views/lib/mixins/action_support.js +5 -3
  24. package/dist/packages/@ember/-internals/views/lib/mixins/child_views_support.js +3 -3
  25. package/dist/packages/@ember/-internals/views/lib/mixins/class_names_support.js +4 -3
  26. package/dist/packages/@ember/-internals/views/lib/mixins/view_support.js +4 -3
  27. package/dist/packages/@ember/-internals/views/lib/system/event_dispatcher.js +6 -12
  28. package/dist/packages/@ember/-internals/views/lib/system/utils.js +3 -2
  29. package/dist/packages/@ember/-internals/views/lib/views/core_view.js +76 -8
  30. package/dist/packages/@ember/-internals/views/lib/views/states.js +4 -3
  31. package/dist/packages/@ember/application/index.js +16 -7
  32. package/dist/packages/@ember/application/instance.js +13 -9
  33. package/dist/packages/@ember/application/namespace.js +7 -6
  34. package/dist/packages/@ember/array/index.js +617 -11
  35. package/dist/packages/@ember/array/make.js +1 -0
  36. package/dist/packages/@ember/array/mutable.js +1 -1
  37. package/dist/packages/@ember/array/proxy.js +8 -5
  38. package/dist/packages/@ember/component/helper.js +4 -4
  39. package/dist/packages/@ember/component/index.js +4 -4
  40. package/dist/packages/@ember/controller/index.js +6 -6
  41. package/dist/packages/@ember/debug/container-debug-adapter.js +5 -4
  42. package/dist/packages/@ember/debug/data-adapter.js +7 -4
  43. package/dist/packages/@ember/debug/index.js +213 -4
  44. package/dist/packages/@ember/debug/lib/assert.js +47 -0
  45. package/dist/packages/@ember/debug/lib/deprecate.js +194 -4
  46. package/dist/packages/@ember/debug/lib/inspect.js +120 -2
  47. package/dist/packages/@ember/debug/lib/warn.js +94 -3
  48. package/dist/packages/@ember/engine/index.js +440 -17
  49. package/dist/packages/@ember/engine/instance.js +175 -11
  50. package/dist/packages/@ember/engine/parent.js +1 -0
  51. package/dist/packages/@ember/helper/index.js +4 -4
  52. package/dist/packages/@ember/instrumentation/index.js +2 -1
  53. package/dist/packages/@ember/modifier/index.js +13 -5
  54. package/dist/packages/@ember/modifier/on.js +15 -0
  55. package/dist/packages/@ember/object/-internals.js +6 -5
  56. package/dist/packages/@ember/object/compat.js +4 -3
  57. package/dist/packages/@ember/object/computed.js +4 -4
  58. package/dist/packages/@ember/object/core.js +861 -14
  59. package/dist/packages/@ember/object/evented.js +4 -4
  60. package/dist/packages/@ember/object/events.js +3 -3
  61. package/dist/packages/@ember/object/index.js +260 -9
  62. package/dist/packages/@ember/object/internals.js +1 -1
  63. package/dist/packages/@ember/object/lib/computed/computed_macros.js +8 -6
  64. package/dist/packages/@ember/object/lib/computed/reduce_computed_macros.js +8 -4
  65. package/dist/packages/@ember/object/mixin.js +6 -5
  66. package/dist/packages/@ember/object/observable.js +103 -9
  67. package/dist/packages/@ember/object/observers.js +3 -3
  68. package/dist/packages/@ember/object/promise-proxy-mixin.js +5 -5
  69. package/dist/packages/@ember/renderer/index.js +4 -4
  70. package/dist/packages/@ember/routing/-internals.js +3 -1
  71. package/dist/packages/@ember/routing/hash-location.js +2 -2
  72. package/dist/packages/@ember/routing/history-location.js +3 -2
  73. package/dist/packages/@ember/routing/index.js +4 -4
  74. package/dist/packages/@ember/routing/lib/dsl.js +2 -1
  75. package/dist/packages/@ember/routing/lib/generate_controller.js +4 -3
  76. package/dist/packages/@ember/routing/lib/router_state.js +26 -1
  77. package/dist/packages/@ember/routing/lib/routing-service.js +107 -9
  78. package/dist/packages/@ember/routing/lib/utils.js +238 -7
  79. package/dist/packages/@ember/routing/none-location.js +3 -2
  80. package/dist/packages/@ember/routing/route.js +1618 -22
  81. package/dist/packages/@ember/routing/router-service.js +638 -12
  82. package/dist/packages/@ember/routing/router.js +1449 -14
  83. package/dist/packages/@ember/runloop/index.js +760 -6
  84. package/dist/packages/@ember/service/index.js +3 -3
  85. package/dist/packages/@ember/template/index.js +4 -4
  86. package/dist/packages/@ember/utils/index.js +2 -1
  87. package/dist/packages/@ember/utils/lib/compare.js +159 -4
  88. package/dist/packages/@ember/utils/lib/is_empty.js +4 -4
  89. package/dist/packages/@ember/utils/lib/type-of.js +110 -1
  90. package/dist/packages/@glimmer/tracking/index.js +3 -3
  91. package/dist/packages/@glimmer/tracking/primitives/cache.js +3 -3
  92. package/dist/packages/ember/barrel.js +28 -13
  93. package/dist/packages/ember/version.js +1 -1
  94. package/dist/packages/ember-testing/lib/adapters/adapter.js +1 -1
  95. package/dist/packages/ember-testing/lib/adapters/qunit.js +2 -1
  96. package/dist/packages/ember-testing/lib/ext/application.js +2 -1
  97. package/dist/packages/ember-testing/lib/ext/rsvp.js +1 -1
  98. package/dist/packages/ember-testing/lib/helpers/and_then.js +2 -1
  99. package/dist/packages/ember-testing/lib/helpers/current_path.js +8 -6
  100. package/dist/packages/ember-testing/lib/helpers/current_route_name.js +8 -6
  101. package/dist/packages/ember-testing/lib/helpers/current_url.js +6 -5
  102. package/dist/packages/ember-testing/lib/helpers/pause_test.js +2 -1
  103. package/dist/packages/ember-testing/lib/helpers/visit.js +4 -3
  104. package/dist/packages/ember-testing/lib/helpers/wait.js +4 -3
  105. package/dist/packages/ember-testing/lib/initializers.js +15 -8
  106. package/dist/packages/ember-testing/lib/setup_for_testing.js +1 -1
  107. package/dist/packages/ember-testing/lib/test/run.js +1 -1
  108. package/dist/packages/router_js/index.js +2 -1
  109. package/dist/packages/shared-chunks/{alias-By_2yu5c.js → alias-Dri0koi2.js} +5 -3
  110. package/dist/packages/shared-chunks/array-3xbmc_4J.js +119 -0
  111. package/dist/packages/shared-chunks/{cache-gDE3bkXq.js → cache-BESCGvbE.js} +667 -1529
  112. package/dist/packages/shared-chunks/{core_view-Cxne2_wu.js → chunk-3SQBS3Y5-Cj4eryg1.js} +1 -88
  113. package/dist/packages/shared-chunks/{index-BXPoca1S.js → index-Llq6dmgX.js} +40 -4660
  114. package/dist/packages/shared-chunks/{is_proxy-Dmis-70B.js → is_proxy-DjvCKvd5.js} +1 -1
  115. package/dist/packages/shared-chunks/{mandatory-setter-1UQhiJOb.js → mandatory-setter-BiXq-dpN.js} +2 -1
  116. package/dist/packages/shared-chunks/{name-z9D9Yibn.js → name-Dx2bGFVv.js} +1 -1
  117. package/dist/packages/shared-chunks/{namespace_search-CBgHTkDh.js → namespace_search-btMaPM-_.js} +2 -2
  118. package/dist/packages/shared-chunks/{property_set-CW4q-uo4.js → property_set-BapAkp3X.js} +5 -4
  119. package/dist/packages/shared-chunks/{registry-DzfcDwii.js → registry-B8WARvkP.js} +3 -2
  120. package/dist/packages/shared-chunks/{router-B-Q1aYBn.js → router-DrLZsJeE.js} +2 -482
  121. package/dist/packages/shared-chunks/{set_properties-DvalyQdu.js → set_properties-BScfxzvI.js} +2 -2
  122. package/dist/packages/shared-chunks/setup-registry-du4pSGZi.js +48 -0
  123. package/dist/packages/shared-chunks/{to-string-D8i3mjEU.js → to-string-B1BmwUkt.js} +1 -1
  124. package/dist/packages/shared-chunks/unrecognized-url-error-zpz-JEoG.js +484 -0
  125. package/docs/data.json +152 -142
  126. package/package.json +2 -2
  127. package/types/stable/@ember/-internals/metal/lib/array.d.ts +1 -2
  128. package/types/stable/@ember/-internals/metal/lib/object-at.d.ts +4 -0
  129. package/types/stable/@ember/-internals/metal/lib/observer.d.ts +2 -1
  130. package/types/stable/@ember/array/index.d.ts +1 -1
  131. package/types/stable/@ember/array/make.d.ts +3 -0
  132. package/types/stable/@ember/debug/index.d.ts +3 -7
  133. package/types/stable/@ember/debug/lib/assert.d.ts +8 -0
  134. package/types/stable/@ember/engine/index.d.ts +1 -1
  135. package/types/stable/@ember/engine/instance.d.ts +2 -2
  136. package/types/stable/@ember/engine/parent.d.ts +3 -0
  137. package/types/stable/@ember/modifier/index.d.ts +1 -3
  138. package/types/stable/@ember/modifier/on.d.ts +5 -0
  139. package/types/stable/@ember/routing/lib/routing-service.d.ts +1 -1
  140. package/types/stable/@ember/routing/route.d.ts +2 -3
  141. package/types/stable/@ember/routing/router-service.d.ts +1 -1
  142. package/types/stable/@ember/routing/router.d.ts +4 -4
  143. package/types/stable/ember/barrel.d.ts +1 -1
  144. package/types/stable/ember/index.d.ts +1 -1
  145. package/types/stable/index.d.ts +5 -0
  146. package/dist/packages/shared-chunks/index-DTxy4Zgx.js +0 -641
  147. package/dist/packages/shared-chunks/index-PYiGj1jp.js +0 -2071
@@ -1,24 +1,871 @@
1
- import '../../shared-chunks/registry-DzfcDwii.js';
2
- import '../-internals/owner/index.js';
3
- import '../../shared-chunks/to-string-D8i3mjEU.js';
4
- import '../../shared-chunks/mandatory-setter-1UQhiJOb.js';
5
- import '../-internals/meta/lib/meta.js';
6
- import '../../shared-chunks/index-DTxy4Zgx.js';
7
- import '../../@glimmer/destroyable/index.js';
1
+ import { g as getFactoryFor, s as setFactoryFor } from '../../shared-chunks/registry-B8WARvkP.js';
2
+ import { getOwner } from '../-internals/owner/index.js';
3
+ import { i as isInternalSymbol } from '../../shared-chunks/to-string-B1BmwUkt.js';
4
+ import { g as guidFor } from '../../shared-chunks/mandatory-setter-BiXq-dpN.js';
5
+ import { meta } from '../-internals/meta/lib/meta.js';
6
+ import '../debug/index.js';
7
+ import { registerDestructor, isDestroyed, isDestroying, destroy } from '../../@glimmer/destroyable/index.js';
8
8
  import '../../@glimmer/validator/index.js';
9
- import '../../shared-chunks/cache-gDE3bkXq.js';
10
9
  import '../../@glimmer/manager/index.js';
11
- import '@embroider/macros';
10
+ import { isDevelopingApp } from '@embroider/macros';
11
+ import { h as hasUnknownProperty, P as PROXY_CONTENT, b as descriptorForProperty, D as DEBUG_INJECTION_FUNCTIONS, f as isClassicDecorator, d as defineProperty, j as activateObserver, k as sendEvent } from '../../shared-chunks/cache-BESCGvbE.js';
12
12
  import '../../shared-chunks/env-BJLX2Arx.js';
13
- import './mixin.js';
13
+ import Mixin, { applyMixin } from './mixin.js';
14
14
  import '../-internals/runtime/lib/mixins/registry_proxy.js';
15
15
  import '../-internals/runtime/lib/mixins/container_proxy.js';
16
16
  import '../-internals/runtime/lib/mixins/comparable.js';
17
- import '../-internals/runtime/lib/mixins/action_handler.js';
17
+ import ActionHandler from '../-internals/runtime/lib/mixins/action_handler.js';
18
18
  import '../-internals/runtime/lib/mixins/-proxy.js';
19
19
  import '../enumerable/mutable.js';
20
20
  import '../-internals/runtime/lib/mixins/target_action_support.js';
21
21
  import '../-internals/runtime/lib/ext/rsvp.js';
22
- export { d as default } from '../../shared-chunks/index-PYiGj1jp.js';
23
- import '../../@glimmer/owner/index.js';
24
- import '../array/lib/make-array.js';
22
+ import makeArray from '../array/lib/make-array.js';
23
+ import { OWNER } from '../../@glimmer/owner/index.js';
24
+ import { assert } from '../debug/lib/assert.js';
25
+
26
+ /**
27
+ @module @ember/object/core
28
+ */
29
+
30
+ function hasSetUnknownProperty(val) {
31
+ return typeof val === 'object' && val !== null && typeof val.setUnknownProperty === 'function';
32
+ }
33
+ function hasToStringExtension(val) {
34
+ return typeof val === 'object' && val !== null && typeof val.toStringExtension === 'function';
35
+ }
36
+ const reopen = Mixin.prototype.reopen;
37
+ const wasApplied = new WeakSet();
38
+ const prototypeMixinMap = new WeakMap();
39
+ const initCalled = isDevelopingApp() ? new WeakSet() : undefined; // only used in debug builds to enable the proxy trap
40
+
41
+ const destroyCalled = new Set();
42
+ function ensureDestroyCalled(instance) {
43
+ if (!destroyCalled.has(instance)) {
44
+ instance.destroy();
45
+ }
46
+ }
47
+ function initialize(obj, properties) {
48
+ let m = meta(obj);
49
+ if (properties !== undefined) {
50
+ (isDevelopingApp() && !(typeof properties === 'object' && properties !== null) && assert('EmberObject.create only accepts objects.', typeof properties === 'object' && properties !== null));
51
+ (isDevelopingApp() && !(!(properties instanceof Mixin)) && assert('EmberObject.create no longer supports mixing in other ' + 'definitions, use .extend & .create separately instead.', !(properties instanceof Mixin)));
52
+ let concatenatedProperties = obj.concatenatedProperties;
53
+ let mergedProperties = obj.mergedProperties;
54
+ let keyNames = Object.keys(properties);
55
+ for (let keyName of keyNames) {
56
+ // SAFETY: this cast as a Record is safe because all object types can be
57
+ // indexed in JS, and we explicitly type it as returning `unknown`, so the
58
+ // result *must* be checked below.
59
+ let value = properties[keyName];
60
+ (isDevelopingApp() && !(!isClassicDecorator(value)) && assert('EmberObject.create no longer supports defining computed ' + 'properties. Define computed properties using extend() or reopen() ' + 'before calling create().', !isClassicDecorator(value)));
61
+ (isDevelopingApp() && !(!(typeof value === 'function' && value.toString().indexOf('._super') !== -1)) && assert('EmberObject.create no longer supports defining methods that call _super.', !(typeof value === 'function' && value.toString().indexOf('._super') !== -1)));
62
+ (isDevelopingApp() && !(!(keyName === 'actions' && ActionHandler.detect(obj))) && assert('`actions` must be provided at extend time, not at create time, ' + 'when Ember.ActionHandler is used (i.e. views, controllers & routes).', !(keyName === 'actions' && ActionHandler.detect(obj))));
63
+ let possibleDesc = descriptorForProperty(obj, keyName, m);
64
+ let isDescriptor = possibleDesc !== undefined;
65
+ if (!isDescriptor) {
66
+ if (concatenatedProperties !== undefined && concatenatedProperties.length > 0 && concatenatedProperties.includes(keyName)) {
67
+ let baseValue = obj[keyName];
68
+ if (baseValue) {
69
+ value = makeArray(baseValue).concat(value);
70
+ } else {
71
+ value = makeArray(value);
72
+ }
73
+ }
74
+ if (mergedProperties !== undefined && mergedProperties.length > 0 && mergedProperties.includes(keyName)) {
75
+ let baseValue = obj[keyName];
76
+ value = Object.assign({}, baseValue, value);
77
+ }
78
+ }
79
+ if (isDescriptor) {
80
+ possibleDesc.set(obj, keyName, value);
81
+ } else if (hasSetUnknownProperty(obj) && !(keyName in obj)) {
82
+ obj.setUnknownProperty(keyName, value);
83
+ } else {
84
+ if (isDevelopingApp()) {
85
+ defineProperty(obj, keyName, null, value, m); // setup mandatory setter
86
+ } else {
87
+ obj[keyName] = value;
88
+ }
89
+ }
90
+ }
91
+ }
92
+
93
+ // using DEBUG here to avoid the extraneous variable when not needed
94
+ if (isDevelopingApp()) {
95
+ initCalled.add(obj);
96
+ }
97
+ obj.init(properties);
98
+ m.unsetInitializing();
99
+ let observerEvents = m.observerEvents();
100
+ if (observerEvents !== undefined) {
101
+ for (let i = 0; i < observerEvents.length; i++) {
102
+ activateObserver(obj, observerEvents[i].event, observerEvents[i].sync);
103
+ }
104
+ }
105
+ sendEvent(obj, 'init', undefined, undefined, m);
106
+ }
107
+
108
+ /**
109
+ `CoreObject` is the base class for all Ember constructs. It establishes a
110
+ class system based on Ember's Mixin system, and provides the basis for the
111
+ Ember Object Model. `CoreObject` should generally not be used directly,
112
+ instead you should use `EmberObject`.
113
+
114
+ ## Usage
115
+
116
+ You can define a class by extending from `CoreObject` using the `extend`
117
+ method:
118
+
119
+ ```js
120
+ const Person = CoreObject.extend({
121
+ name: 'Tomster',
122
+ });
123
+ ```
124
+
125
+ For detailed usage, see the [Object Model](https://guides.emberjs.com/release/object-model/)
126
+ section of the guides.
127
+
128
+ ## Usage with Native Classes
129
+
130
+ Native JavaScript `class` syntax can be used to extend from any `CoreObject`
131
+ based class:
132
+
133
+ ```js
134
+ class Person extends CoreObject {
135
+ init() {
136
+ super.init(...arguments);
137
+ this.name = 'Tomster';
138
+ }
139
+ }
140
+ ```
141
+
142
+ Some notes about `class` usage:
143
+
144
+ * `new` syntax is not currently supported with classes that extend from
145
+ `EmberObject` or `CoreObject`. You must continue to use the `create` method
146
+ when making new instances of classes, even if they are defined using native
147
+ class syntax. If you want to use `new` syntax, consider creating classes
148
+ which do _not_ extend from `EmberObject` or `CoreObject`. Ember features,
149
+ such as computed properties and decorators, will still work with base-less
150
+ classes.
151
+ * Instead of using `this._super()`, you must use standard `super` syntax in
152
+ native classes. See the [MDN docs on classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Super_class_calls_with_super)
153
+ for more details.
154
+ * Native classes support using [constructors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Constructor)
155
+ to set up newly-created instances. Ember uses these to, among other things,
156
+ support features that need to retrieve other entities by name, like Service
157
+ injection and `getOwner`. To ensure your custom instance setup logic takes
158
+ place after this important work is done, avoid using the `constructor` in
159
+ favor of `init`.
160
+ * Properties passed to `create` will be available on the instance by the time
161
+ `init` runs, so any code that requires these values should work at that
162
+ time.
163
+ * Using native classes, and switching back to the old Ember Object model is
164
+ fully supported.
165
+
166
+ @class CoreObject
167
+ @public
168
+ */
169
+
170
+ class CoreObject {
171
+ /** @internal */
172
+ [OWNER];
173
+ constructor(owner) {
174
+ this[OWNER] = owner;
175
+
176
+ // prepare prototype...
177
+ this.constructor.proto();
178
+ let self;
179
+ if (isDevelopingApp() && hasUnknownProperty(this)) {
180
+ let messageFor = (obj, property) => {
181
+ return `You attempted to access the \`${String(property)}\` property (of ${obj}).\n` + `Since Ember 3.1, this is usually fine as you no longer need to use \`.get()\`\n` + `to access computed properties. However, in this case, the object in question\n` + `is a special kind of Ember object (a proxy). Therefore, it is still necessary\n` + `to use \`.get('${String(property)}')\` in this case.\n\n` + `If you encountered this error because of third-party code that you don't control,\n` + `there is more information at https://github.com/emberjs/ember.js/issues/16148, and\n` + `you can help us improve this error message by telling us more about what happened in\n` + `this situation.`;
182
+ };
183
+
184
+ /* globals Proxy Reflect */
185
+ self = new Proxy(this, {
186
+ get(target, property, receiver) {
187
+ if (property === PROXY_CONTENT) {
188
+ return target;
189
+ } else if (
190
+ // init called will be set on the proxy, not the target, so get with the receiver
191
+ !initCalled.has(receiver) || typeof property === 'symbol' || isInternalSymbol(property) || property === 'toJSON' || property === 'toString' || property === 'toStringExtension' || property === 'didDefineProperty' || property === 'willWatchProperty' || property === 'didUnwatchProperty' || property === 'didAddListener' || property === 'didRemoveListener' || property === 'isDescriptor' || property === '_onLookup' || property in target) {
192
+ return Reflect.get(target, property, receiver);
193
+ }
194
+ let value = target.unknownProperty.call(receiver, property);
195
+ if (typeof value !== 'function') {
196
+ (isDevelopingApp() && !(value === undefined || value === null) && assert(messageFor(receiver, property), value === undefined || value === null));
197
+ }
198
+ }
199
+ });
200
+ } else {
201
+ self = this;
202
+ }
203
+ const destroyable = self;
204
+ registerDestructor(self, ensureDestroyCalled, true);
205
+ registerDestructor(self, () => destroyable.willDestroy());
206
+
207
+ // disable chains
208
+ let m = meta(self);
209
+ m.setInitializing();
210
+
211
+ // only return when in debug builds and `self` is the proxy created above
212
+ if (isDevelopingApp() && self !== this) {
213
+ return self;
214
+ }
215
+ }
216
+ reopen(...args) {
217
+ applyMixin(this, args);
218
+ return this;
219
+ }
220
+
221
+ /**
222
+ An overridable method called when objects are instantiated. By default,
223
+ does nothing unless it is overridden during class definition.
224
+ Example:
225
+ ```javascript
226
+ import EmberObject from '@ember/object';
227
+ const Person = EmberObject.extend({
228
+ init() {
229
+ alert(`Name is ${this.get('name')}`);
230
+ }
231
+ });
232
+ let steve = Person.create({
233
+ name: 'Steve'
234
+ });
235
+ // alerts 'Name is Steve'.
236
+ ```
237
+ NOTE: If you do override `init` for a framework class like `Component`
238
+ from `@ember/component`, be sure to call `this._super(...arguments)`
239
+ in your `init` declaration!
240
+ If you don't, Ember may not have an opportunity to
241
+ do important setup work, and you'll see strange behavior in your
242
+ application.
243
+ @method init
244
+ @public
245
+ */
246
+ init(_properties) {}
247
+
248
+ /**
249
+ Defines the properties that will be concatenated from the superclass
250
+ (instead of overridden).
251
+ By default, when you extend an Ember class a property defined in
252
+ the subclass overrides a property with the same name that is defined
253
+ in the superclass. However, there are some cases where it is preferable
254
+ to build up a property's value by combining the superclass' property
255
+ value with the subclass' value. An example of this in use within Ember
256
+ is the `classNames` property of `Component` from `@ember/component`.
257
+ Here is some sample code showing the difference between a concatenated
258
+ property and a normal one:
259
+ ```javascript
260
+ import EmberObject from '@ember/object';
261
+ const Bar = EmberObject.extend({
262
+ // Configure which properties to concatenate
263
+ concatenatedProperties: ['concatenatedProperty'],
264
+ someNonConcatenatedProperty: ['bar'],
265
+ concatenatedProperty: ['bar']
266
+ });
267
+ const FooBar = Bar.extend({
268
+ someNonConcatenatedProperty: ['foo'],
269
+ concatenatedProperty: ['foo']
270
+ });
271
+ let fooBar = FooBar.create();
272
+ fooBar.get('someNonConcatenatedProperty'); // ['foo']
273
+ fooBar.get('concatenatedProperty'); // ['bar', 'foo']
274
+ ```
275
+ This behavior extends to object creation as well. Continuing the
276
+ above example:
277
+ ```javascript
278
+ let fooBar = FooBar.create({
279
+ someNonConcatenatedProperty: ['baz'],
280
+ concatenatedProperty: ['baz']
281
+ })
282
+ fooBar.get('someNonConcatenatedProperty'); // ['baz']
283
+ fooBar.get('concatenatedProperty'); // ['bar', 'foo', 'baz']
284
+ ```
285
+ Adding a single property that is not an array will just add it in the array:
286
+ ```javascript
287
+ let fooBar = FooBar.create({
288
+ concatenatedProperty: 'baz'
289
+ })
290
+ view.get('concatenatedProperty'); // ['bar', 'foo', 'baz']
291
+ ```
292
+ Using the `concatenatedProperties` property, we can tell Ember to mix the
293
+ content of the properties.
294
+ In `Component` the `classNames`, `classNameBindings` and
295
+ `attributeBindings` properties are concatenated.
296
+ This feature is available for you to use throughout the Ember object model,
297
+ although typical app developers are likely to use it infrequently. Since
298
+ it changes expectations about behavior of properties, you should properly
299
+ document its usage in each individual concatenated property (to not
300
+ mislead your users to think they can override the property in a subclass).
301
+ @property concatenatedProperties
302
+ @type Array
303
+ @default null
304
+ @public
305
+ */
306
+
307
+ /**
308
+ Defines the properties that will be merged from the superclass
309
+ (instead of overridden).
310
+ By default, when you extend an Ember class a property defined in
311
+ the subclass overrides a property with the same name that is defined
312
+ in the superclass. However, there are some cases where it is preferable
313
+ to build up a property's value by merging the superclass property value
314
+ with the subclass property's value. An example of this in use within Ember
315
+ is the `queryParams` property of routes.
316
+ Here is some sample code showing the difference between a merged
317
+ property and a normal one:
318
+ ```javascript
319
+ import EmberObject from '@ember/object';
320
+ const Bar = EmberObject.extend({
321
+ // Configure which properties are to be merged
322
+ mergedProperties: ['mergedProperty'],
323
+ someNonMergedProperty: {
324
+ nonMerged: 'superclass value of nonMerged'
325
+ },
326
+ mergedProperty: {
327
+ page: { replace: false },
328
+ limit: { replace: true }
329
+ }
330
+ });
331
+ const FooBar = Bar.extend({
332
+ someNonMergedProperty: {
333
+ completelyNonMerged: 'subclass value of nonMerged'
334
+ },
335
+ mergedProperty: {
336
+ limit: { replace: false }
337
+ }
338
+ });
339
+ let fooBar = FooBar.create();
340
+ fooBar.get('someNonMergedProperty');
341
+ // => { completelyNonMerged: 'subclass value of nonMerged' }
342
+ //
343
+ // Note the entire object, including the nonMerged property of
344
+ // the superclass object, has been replaced
345
+ fooBar.get('mergedProperty');
346
+ // => {
347
+ // page: {replace: false},
348
+ // limit: {replace: false}
349
+ // }
350
+ //
351
+ // Note the page remains from the superclass, and the
352
+ // `limit` property's value of `false` has been merged from
353
+ // the subclass.
354
+ ```
355
+ This behavior is not available during object `create` calls. It is only
356
+ available at `extend` time.
357
+ In `Route` the `queryParams` property is merged.
358
+ This feature is available for you to use throughout the Ember object model,
359
+ although typical app developers are likely to use it infrequently. Since
360
+ it changes expectations about behavior of properties, you should properly
361
+ document its usage in each individual merged property (to not
362
+ mislead your users to think they can override the property in a subclass).
363
+ @property mergedProperties
364
+ @type Array
365
+ @default null
366
+ @public
367
+ */
368
+
369
+ /**
370
+ Destroyed object property flag.
371
+ if this property is `true` the observers and bindings were already
372
+ removed by the effect of calling the `destroy()` method.
373
+ @property isDestroyed
374
+ @default false
375
+ @public
376
+ */
377
+ get isDestroyed() {
378
+ return isDestroyed(this);
379
+ }
380
+ set isDestroyed(_value) {
381
+ (isDevelopingApp() && !(false) && assert(`You cannot set \`${this}.isDestroyed\` directly, please use \`.destroy()\`.`, false));
382
+ }
383
+
384
+ /**
385
+ Destruction scheduled flag. The `destroy()` method has been called.
386
+ The object stays intact until the end of the run loop at which point
387
+ the `isDestroyed` flag is set.
388
+ @property isDestroying
389
+ @default false
390
+ @public
391
+ */
392
+ get isDestroying() {
393
+ return isDestroying(this);
394
+ }
395
+ set isDestroying(_value) {
396
+ (isDevelopingApp() && !(false) && assert(`You cannot set \`${this}.isDestroying\` directly, please use \`.destroy()\`.`, false));
397
+ }
398
+
399
+ /**
400
+ Destroys an object by setting the `isDestroyed` flag and removing its
401
+ metadata, which effectively destroys observers and bindings.
402
+ If you try to set a property on a destroyed object, an exception will be
403
+ raised.
404
+ Note that destruction is scheduled for the end of the run loop and does not
405
+ happen immediately. It will set an isDestroying flag immediately.
406
+ @method destroy
407
+ @return {EmberObject} receiver
408
+ @public
409
+ */
410
+ destroy() {
411
+ // Used to ensure that manually calling `.destroy()` does not immediately call destroy again
412
+ destroyCalled.add(this);
413
+ try {
414
+ destroy(this);
415
+ } finally {
416
+ destroyCalled.delete(this);
417
+ }
418
+ return this;
419
+ }
420
+
421
+ /**
422
+ Override to implement teardown.
423
+ @method willDestroy
424
+ @public
425
+ */
426
+ willDestroy() {}
427
+
428
+ /**
429
+ Returns a string representation which attempts to provide more information
430
+ than Javascript's `toString` typically does, in a generic way for all Ember
431
+ objects.
432
+ ```javascript
433
+ import EmberObject from '@ember/object';
434
+ const Person = EmberObject.extend();
435
+ person = Person.create();
436
+ person.toString(); //=> "<Person:ember1024>"
437
+ ```
438
+ If the object's class is not defined on an Ember namespace, it will
439
+ indicate it is a subclass of the registered superclass:
440
+ ```javascript
441
+ const Student = Person.extend();
442
+ let student = Student.create();
443
+ student.toString(); //=> "<(subclass of Person):ember1025>"
444
+ ```
445
+ If the method `toStringExtension` is defined, its return value will be
446
+ included in the output.
447
+ ```javascript
448
+ const Teacher = Person.extend({
449
+ toStringExtension() {
450
+ return this.get('fullName');
451
+ }
452
+ });
453
+ teacher = Teacher.create();
454
+ teacher.toString(); //=> "<Teacher:ember1026:Tom Dale>"
455
+ ```
456
+ @method toString
457
+ @return {String} string representation
458
+ @public
459
+ */
460
+ toString() {
461
+ let extension = hasToStringExtension(this) ? `:${this.toStringExtension()}` : '';
462
+ return `<${getFactoryFor(this) || '(unknown)'}:${guidFor(this)}${extension}>`;
463
+ }
464
+
465
+ /**
466
+ Creates a new subclass.
467
+ ```javascript
468
+ import EmberObject from '@ember/object';
469
+ const Person = EmberObject.extend({
470
+ say(thing) {
471
+ alert(thing);
472
+ }
473
+ });
474
+ ```
475
+ This defines a new subclass of EmberObject: `Person`. It contains one method: `say()`.
476
+ You can also create a subclass from any existing class by calling its `extend()` method.
477
+ For example, you might want to create a subclass of Ember's built-in `Component` class:
478
+ ```javascript
479
+ import Component from '@ember/component';
480
+ const PersonComponent = Component.extend({
481
+ tagName: 'li',
482
+ classNameBindings: ['isAdministrator']
483
+ });
484
+ ```
485
+ When defining a subclass, you can override methods but still access the
486
+ implementation of your parent class by calling the special `_super()` method:
487
+ ```javascript
488
+ import EmberObject from '@ember/object';
489
+ const Person = EmberObject.extend({
490
+ say(thing) {
491
+ let name = this.get('name');
492
+ alert(`${name} says: ${thing}`);
493
+ }
494
+ });
495
+ const Soldier = Person.extend({
496
+ say(thing) {
497
+ this._super(`${thing}, sir!`);
498
+ },
499
+ march(numberOfHours) {
500
+ alert(`${this.get('name')} marches for ${numberOfHours} hours.`);
501
+ }
502
+ });
503
+ let yehuda = Soldier.create({
504
+ name: 'Yehuda Katz'
505
+ });
506
+ yehuda.say('Yes'); // alerts "Yehuda Katz says: Yes, sir!"
507
+ ```
508
+ The `create()` on line #17 creates an *instance* of the `Soldier` class.
509
+ The `extend()` on line #8 creates a *subclass* of `Person`. Any instance
510
+ of the `Person` class will *not* have the `march()` method.
511
+ You can also pass `Mixin` classes to add additional properties to the subclass.
512
+ ```javascript
513
+ import EmberObject from '@ember/object';
514
+ import Mixin from '@ember/object/mixin';
515
+ const Person = EmberObject.extend({
516
+ say(thing) {
517
+ alert(`${this.get('name')} says: ${thing}`);
518
+ }
519
+ });
520
+ const SingingMixin = Mixin.create({
521
+ sing(thing) {
522
+ alert(`${this.get('name')} sings: la la la ${thing}`);
523
+ }
524
+ });
525
+ const BroadwayStar = Person.extend(SingingMixin, {
526
+ dance() {
527
+ alert(`${this.get('name')} dances: tap tap tap tap `);
528
+ }
529
+ });
530
+ ```
531
+ The `BroadwayStar` class contains three methods: `say()`, `sing()`, and `dance()`.
532
+ @method extend
533
+ @static
534
+ @for @ember/object
535
+ @param {Mixin} [mixins]* One or more Mixin classes
536
+ @param {Object} [arguments]* Object containing values to use within the new class
537
+ @public
538
+ */
539
+
540
+ static extend(...mixins) {
541
+ let Class = class extends this {};
542
+ reopen.apply(Class.PrototypeMixin, mixins);
543
+ return Class;
544
+ }
545
+
546
+ /**
547
+ Creates an instance of a class. Accepts either no arguments, or an object
548
+ containing values to initialize the newly instantiated object with.
549
+ ```javascript
550
+ import EmberObject from '@ember/object';
551
+ const Person = EmberObject.extend({
552
+ helloWorld() {
553
+ alert(`Hi, my name is ${this.get('name')}`);
554
+ }
555
+ });
556
+ let tom = Person.create({
557
+ name: 'Tom Dale'
558
+ });
559
+ tom.helloWorld(); // alerts "Hi, my name is Tom Dale".
560
+ ```
561
+ `create` will call the `init` function if defined during
562
+ `AnyObject.extend`
563
+ If no arguments are passed to `create`, it will not set values to the new
564
+ instance during initialization:
565
+ ```javascript
566
+ let noName = Person.create();
567
+ noName.helloWorld(); // alerts undefined
568
+ ```
569
+ NOTE: For performance reasons, you cannot declare methods or computed
570
+ properties during `create`. You should instead declare methods and computed
571
+ properties when using `extend`.
572
+ @method create
573
+ @for @ember/object
574
+ @static
575
+ @param [arguments]*
576
+ @public
577
+ */
578
+
579
+ static create(...args) {
580
+ let props = args[0];
581
+ let instance;
582
+ if (props !== undefined) {
583
+ instance = new this(getOwner(props));
584
+ // TODO(SAFETY): at present, we cannot actually rely on this being set,
585
+ // because a number of acceptance tests are (incorrectly? Unclear!)
586
+ // relying on the ability to run through this path with `factory` being
587
+ // `undefined`. It's *possible* that actually means that the type for
588
+ // `setFactoryFor()` should allow `undefined`, but we typed it the other
589
+ // way for good reason! Accordingly, this *casts* `factory`, and the
590
+ // commented-out `assert()` is here in the hope that we can enable it
591
+ // after addressing tests *or* updating the call signature here.
592
+ let factory = getFactoryFor(props);
593
+ // assert(`missing factory when creating object ${instance}`, factory !== undefined);
594
+ setFactoryFor(instance, factory);
595
+ } else {
596
+ instance = new this();
597
+ }
598
+ if (args.length <= 1) {
599
+ initialize(instance, props);
600
+ } else {
601
+ initialize(instance, flattenProps.apply(this, args));
602
+ }
603
+
604
+ // SAFETY: The `initialize` call is responsible to merge the prototype chain
605
+ // so that this holds.
606
+ return instance;
607
+ }
608
+
609
+ /**
610
+ Augments a constructor's prototype with additional
611
+ properties and functions:
612
+ ```javascript
613
+ import EmberObject from '@ember/object';
614
+ const MyObject = EmberObject.extend({
615
+ name: 'an object'
616
+ });
617
+ o = MyObject.create();
618
+ o.get('name'); // 'an object'
619
+ MyObject.reopen({
620
+ say(msg) {
621
+ console.log(msg);
622
+ }
623
+ });
624
+ o2 = MyObject.create();
625
+ o2.say('hello'); // logs "hello"
626
+ o.say('goodbye'); // logs "goodbye"
627
+ ```
628
+ To add functions and properties to the constructor itself,
629
+ see `reopenClass`
630
+ @method reopen
631
+ @for @ember/object
632
+ @static
633
+ @public
634
+ */
635
+ static reopen(...args) {
636
+ this.willReopen();
637
+ reopen.apply(this.PrototypeMixin, args);
638
+ return this;
639
+ }
640
+ static willReopen() {
641
+ let p = this.prototype;
642
+ if (wasApplied.has(p)) {
643
+ wasApplied.delete(p);
644
+
645
+ // If the base mixin already exists and was applied, create a new mixin to
646
+ // make sure that it gets properly applied. Reusing the same mixin after
647
+ // the first `proto` call will cause it to get skipped.
648
+ if (prototypeMixinMap.has(this)) {
649
+ prototypeMixinMap.set(this, Mixin.create(this.PrototypeMixin));
650
+ }
651
+ }
652
+ }
653
+
654
+ /**
655
+ Augments a constructor's own properties and functions:
656
+ ```javascript
657
+ import EmberObject from '@ember/object';
658
+ const MyObject = EmberObject.extend({
659
+ name: 'an object'
660
+ });
661
+ MyObject.reopenClass({
662
+ canBuild: false
663
+ });
664
+ MyObject.canBuild; // false
665
+ o = MyObject.create();
666
+ ```
667
+ In other words, this creates static properties and functions for the class.
668
+ These are only available on the class and not on any instance of that class.
669
+ ```javascript
670
+ import EmberObject from '@ember/object';
671
+ const Person = EmberObject.extend({
672
+ name: '',
673
+ sayHello() {
674
+ alert(`Hello. My name is ${this.get('name')}`);
675
+ }
676
+ });
677
+ Person.reopenClass({
678
+ species: 'Homo sapiens',
679
+ createPerson(name) {
680
+ return Person.create({ name });
681
+ }
682
+ });
683
+ let tom = Person.create({
684
+ name: 'Tom Dale'
685
+ });
686
+ let yehuda = Person.createPerson('Yehuda Katz');
687
+ tom.sayHello(); // "Hello. My name is Tom Dale"
688
+ yehuda.sayHello(); // "Hello. My name is Yehuda Katz"
689
+ alert(Person.species); // "Homo sapiens"
690
+ ```
691
+ Note that `species` and `createPerson` are *not* valid on the `tom` and `yehuda`
692
+ variables. They are only valid on `Person`.
693
+ To add functions and properties to instances of
694
+ a constructor by extending the constructor's prototype
695
+ see `reopen`
696
+ @method reopenClass
697
+ @for @ember/object
698
+ @static
699
+ @public
700
+ */
701
+ static reopenClass(...mixins) {
702
+ applyMixin(this, mixins);
703
+ return this;
704
+ }
705
+ static detect(obj) {
706
+ if ('function' !== typeof obj) {
707
+ return false;
708
+ }
709
+ while (obj) {
710
+ if (obj === this) {
711
+ return true;
712
+ }
713
+ obj = obj.superclass;
714
+ }
715
+ return false;
716
+ }
717
+ static detectInstance(obj) {
718
+ return obj instanceof this;
719
+ }
720
+
721
+ /**
722
+ In some cases, you may want to annotate computed properties with additional
723
+ metadata about how they function or what values they operate on. For
724
+ example, computed property functions may close over variables that are then
725
+ no longer available for introspection.
726
+ You can pass a hash of these values to a computed property like this:
727
+ ```javascript
728
+ import { computed } from '@ember/object';
729
+ person: computed(function() {
730
+ let personId = this.get('personId');
731
+ return Person.create({ id: personId });
732
+ }).meta({ type: Person })
733
+ ```
734
+ Once you've done this, you can retrieve the values saved to the computed
735
+ property from your class like this:
736
+ ```javascript
737
+ MyClass.metaForProperty('person');
738
+ ```
739
+ This will return the original hash that was passed to `meta()`.
740
+ @static
741
+ @method metaForProperty
742
+ @param key {String} property name
743
+ @private
744
+ */
745
+ static metaForProperty(key) {
746
+ let proto = this.proto(); // ensure prototype is initialized
747
+ let possibleDesc = descriptorForProperty(proto, key);
748
+ (isDevelopingApp() && !(possibleDesc !== undefined) && assert(`metaForProperty() could not find a computed property with key '${key}'.`, possibleDesc !== undefined));
749
+ return possibleDesc._meta || {};
750
+ }
751
+
752
+ /**
753
+ Iterate over each computed property for the class, passing its name
754
+ and any associated metadata (see `metaForProperty`) to the callback.
755
+ @static
756
+ @method eachComputedProperty
757
+ @param {Function} callback
758
+ @param {Object} binding
759
+ @private
760
+ */
761
+ static eachComputedProperty(callback, binding = this) {
762
+ this.proto(); // ensure prototype is initialized
763
+ let empty = {};
764
+ meta(this.prototype).forEachDescriptors((name, descriptor) => {
765
+ if (descriptor.enumerable) {
766
+ let meta = descriptor._meta || empty;
767
+ callback.call(binding, name, meta);
768
+ }
769
+ });
770
+ }
771
+ static get PrototypeMixin() {
772
+ let prototypeMixin = prototypeMixinMap.get(this);
773
+ if (prototypeMixin === undefined) {
774
+ prototypeMixin = Mixin.create();
775
+ prototypeMixin.ownerConstructor = this;
776
+ prototypeMixinMap.set(this, prototypeMixin);
777
+ }
778
+ return prototypeMixin;
779
+ }
780
+ static get superclass() {
781
+ let c = Object.getPrototypeOf(this);
782
+ return c !== Function.prototype ? c : undefined;
783
+ }
784
+ static proto() {
785
+ let p = this.prototype;
786
+ if (!wasApplied.has(p)) {
787
+ wasApplied.add(p);
788
+ let parent = this.superclass;
789
+ if (parent) {
790
+ parent.proto();
791
+ }
792
+
793
+ // If the prototype mixin exists, apply it. In the case of native classes,
794
+ // it will not exist (unless the class has been reopened).
795
+ if (prototypeMixinMap.has(this)) {
796
+ this.PrototypeMixin.apply(p);
797
+ }
798
+ }
799
+ return p;
800
+ }
801
+ static toString() {
802
+ return `<${getFactoryFor(this) || '(unknown)'}:constructor>`;
803
+ }
804
+ static isClass = true;
805
+ static isMethod = false;
806
+ static _onLookup;
807
+ static _lazyInjections;
808
+ }
809
+ function flattenProps(...props) {
810
+ let initProperties = {};
811
+ for (let properties of props) {
812
+ (isDevelopingApp() && !(!(properties instanceof Mixin)) && assert('EmberObject.create no longer supports mixing in other ' + 'definitions, use .extend & .create separately instead.', !(properties instanceof Mixin)));
813
+ let keyNames = Object.keys(properties);
814
+ for (let j = 0, k = keyNames.length; j < k; j++) {
815
+ let keyName = keyNames[j];
816
+ let value = properties[keyName];
817
+ initProperties[keyName] = value;
818
+ }
819
+ }
820
+ return initProperties;
821
+ }
822
+ if (isDevelopingApp()) {
823
+ /**
824
+ Provides lookup-time type validation for injected properties.
825
+ @private
826
+ @method _onLookup
827
+ */
828
+ CoreObject._onLookup = function injectedPropertyAssertion(debugContainerKey) {
829
+ let [type] = debugContainerKey.split(':');
830
+ let proto = this.proto();
831
+ for (let key in proto) {
832
+ let desc = descriptorForProperty(proto, key);
833
+ if (desc && DEBUG_INJECTION_FUNCTIONS.has(desc._getter)) {
834
+ (isDevelopingApp() && !(type === 'controller' || DEBUG_INJECTION_FUNCTIONS.get(desc._getter).type !== 'controller') && assert(`Defining \`${key}\` as an injected controller property on a non-controller (\`${debugContainerKey}\`) is not allowed.`, type === 'controller' || DEBUG_INJECTION_FUNCTIONS.get(desc._getter).type !== 'controller'));
835
+ }
836
+ }
837
+ };
838
+
839
+ /**
840
+ Returns a hash of property names and container names that injected
841
+ properties will lookup on the container lazily.
842
+ @method _lazyInjections
843
+ @return {Object} Hash of all lazy injected property keys to container names
844
+ @private
845
+ */
846
+ CoreObject._lazyInjections = function () {
847
+ let injections = {};
848
+ let proto = this.proto();
849
+ let key;
850
+ let desc;
851
+ for (key in proto) {
852
+ desc = descriptorForProperty(proto, key);
853
+ if (desc && DEBUG_INJECTION_FUNCTIONS.has(desc._getter)) {
854
+ let {
855
+ namespace,
856
+ source,
857
+ type,
858
+ name
859
+ } = DEBUG_INJECTION_FUNCTIONS.get(desc._getter);
860
+ injections[key] = {
861
+ namespace,
862
+ source,
863
+ specifier: `${type}:${name || key}`
864
+ };
865
+ }
866
+ }
867
+ return injections;
868
+ };
869
+ }
870
+
871
+ export { CoreObject as default };