ember-source 4.5.0-alpha.4 → 4.5.0-beta.2

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 (126) hide show
  1. package/CHANGELOG.md +13 -4
  2. package/blueprints-js/-addon-import.js +48 -0
  3. package/blueprints-js/acceptance-test/mocha-files/tests/acceptance/__name__-test.js +24 -0
  4. package/blueprints-js/acceptance-test/mocha-rfc-232-files/tests/acceptance/__name__-test.js +13 -0
  5. package/blueprints-js/acceptance-test/qunit-files/tests/acceptance/__name__-test.js +12 -0
  6. package/blueprints-js/acceptance-test/qunit-rfc-232-files/tests/acceptance/__name__-test.js +13 -0
  7. package/blueprints-js/component/files/__root__/__path__/__name__.js +3 -0
  8. package/blueprints-js/component/files/__root__/__templatepath__/__templatename__.hbs +1 -0
  9. package/blueprints-js/component-addon/files/__root__/__path__/__name__.js +1 -0
  10. package/blueprints-js/component-class/files/__root__/__path__/__name__.js +3 -0
  11. package/blueprints-js/component-class-addon/files/__root__/__path__/__name__.js +1 -0
  12. package/blueprints-js/component-test/mocha-0.12-files/__root__/__testType__/__path__/__test__.js +34 -0
  13. package/blueprints-js/component-test/mocha-files/__root__/__testType__/__path__/__test__.js +36 -0
  14. package/blueprints-js/component-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js +38 -0
  15. package/blueprints-js/component-test/qunit-files/__root__/__testType__/__path__/__test__.js +31 -0
  16. package/blueprints-js/component-test/qunit-rfc-232-files/__root__/__testType__/__path__/__test__.js +36 -0
  17. package/blueprints-js/controller/files/__root__/__path__/__name__.js +3 -0
  18. package/blueprints-js/controller-test/mocha-0.12-files/__root__/__testType__/__path__/__test__.js +16 -0
  19. package/blueprints-js/controller-test/mocha-files/__root__/__testType__/__path__/__test__.js +18 -0
  20. package/blueprints-js/controller-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js +13 -0
  21. package/blueprints-js/controller-test/qunit-files/__root__/__testType__/__path__/__test__.js +12 -0
  22. package/blueprints-js/controller-test/qunit-rfc-232-files/__root__/__testType__/__path__/__test__.js +12 -0
  23. package/blueprints-js/helper/files/__root__/__collection__/__name__.js +5 -0
  24. package/blueprints-js/helper/mu-files/__root__/__collection__/__name__.js +7 -0
  25. package/blueprints-js/helper-addon/files/__root__/__path__/__name__.js +1 -0
  26. package/blueprints-js/helper-test/mocha-0.12-files/__root__/__testType__/__collection__/__name__-test.js +26 -0
  27. package/blueprints-js/helper-test/mocha-files/__root__/__testType__/__collection__/__name__-test.js +28 -0
  28. package/blueprints-js/helper-test/mocha-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js +18 -0
  29. package/blueprints-js/helper-test/qunit-files/__root__/__testType__/__collection__/__name__-test.js +15 -0
  30. package/blueprints-js/helper-test/qunit-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js +17 -0
  31. package/blueprints-js/initializer/files/__root__/initializers/__name__.js +5 -0
  32. package/blueprints-js/initializer-addon/files/__root__/__path__/__name__.js +1 -0
  33. package/blueprints-js/initializer-test/mocha-files/__root__/__testType__/__path__/__name__-test.js +28 -0
  34. package/blueprints-js/initializer-test/mocha-rfc-232-files/__root__/__testType__/__path__/__name__-test.js +31 -0
  35. package/blueprints-js/initializer-test/qunit-files/__root__/__testType__/__path__/__name__-test.js +25 -0
  36. package/blueprints-js/initializer-test/qunit-rfc-232-files/__root__/__testType__/__path__/__name__-test.js +37 -0
  37. package/blueprints-js/instance-initializer/files/__root__/instance-initializers/__name__.js +5 -0
  38. package/blueprints-js/instance-initializer-addon/files/__root__/__path__/__name__.js +1 -0
  39. package/blueprints-js/instance-initializer-test/mocha-files/__root__/__testType__/__path__/__name__-test.js +30 -0
  40. package/blueprints-js/instance-initializer-test/mocha-rfc-232-files/__root__/__testType__/__path__/__name__-test.js +32 -0
  41. package/blueprints-js/instance-initializer-test/qunit-files/__root__/__testType__/__path__/__name__-test.js +26 -0
  42. package/blueprints-js/instance-initializer-test/qunit-rfc-232-files/__root__/__testType__/__path__/__name__-test.js +39 -0
  43. package/blueprints-js/mixin/files/__root__/mixins/__name__.js +3 -0
  44. package/blueprints-js/mixin-test/mocha-files/__root__/__testType__/__name__-test.js +13 -0
  45. package/blueprints-js/mixin-test/mocha-rfc-232-files/__root__/__testType__/__name__-test.js +13 -0
  46. package/blueprints-js/mixin-test/qunit-files/__root__/__testType__/__name__-test.js +12 -0
  47. package/blueprints-js/mixin-test/qunit-rfc-232-files/__root__/__testType__/__name__-test.js +12 -0
  48. package/blueprints-js/route/files/__root__/__path__/__name__.js +9 -0
  49. package/blueprints-js/route/files/__root__/__templatepath__/__templatename__.hbs +2 -0
  50. package/blueprints-js/route-addon/files/__root__/__path__/__name__.js +1 -0
  51. package/blueprints-js/route-addon/files/__root__/__templatepath__/__templatename__.js +1 -0
  52. package/blueprints-js/route-test/mocha-0.12-files/__root__/__testType__/__path__/__test__.js +15 -0
  53. package/blueprints-js/route-test/mocha-files/__root__/__testType__/__path__/__test__.js +17 -0
  54. package/blueprints-js/route-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js +12 -0
  55. package/blueprints-js/route-test/qunit-files/__root__/__testType__/__path__/__test__.js +11 -0
  56. package/blueprints-js/route-test/qunit-rfc-232-files/__root__/__testType__/__path__/__test__.js +11 -0
  57. package/blueprints-js/service/files/__root__/__path__/__name__.js +3 -0
  58. package/blueprints-js/service-test/mocha-0.12-files/__root__/__testType__/__path__/__test__.js +16 -0
  59. package/blueprints-js/service-test/mocha-files/__root__/__testType__/__path__/__test__.js +18 -0
  60. package/blueprints-js/service-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js +13 -0
  61. package/blueprints-js/service-test/qunit-files/__root__/__testType__/__path__/__test__.js +12 -0
  62. package/blueprints-js/service-test/qunit-rfc-232-files/__root__/__testType__/__path__/__test__.js +12 -0
  63. package/blueprints-js/template/files/__root__/__path__/__name__.hbs +0 -0
  64. package/blueprints-js/test-framework-detector.js +60 -0
  65. package/blueprints-js/util/files/__root__/utils/__name__.js +3 -0
  66. package/blueprints-js/util-test/mocha-files/__root__/__testType__/__name__-test.js +11 -0
  67. package/blueprints-js/util-test/mocha-rfc-232-files/__root__/__testType__/__name__-test.js +11 -0
  68. package/blueprints-js/util-test/qunit-files/__root__/__testType__/__name__-test.js +10 -0
  69. package/blueprints-js/util-test/qunit-rfc-232-files/__root__/__testType__/__name__-test.js +10 -0
  70. package/build-metadata.json +3 -3
  71. package/dist/ember-template-compiler.js +12 -5
  72. package/dist/ember-template-compiler.map +1 -1
  73. package/dist/ember-testing.js +1 -1
  74. package/dist/ember-testing.map +1 -1
  75. package/dist/ember.debug.js +722 -1001
  76. package/dist/ember.debug.map +1 -1
  77. package/dist/header/license.js +1 -1
  78. package/dist/packages/@ember/-internals/container/index.js +2 -2
  79. package/dist/packages/@ember/-internals/glimmer/index.js +33 -23
  80. package/dist/packages/@ember/-internals/metal/index.js +19 -7
  81. package/dist/packages/@ember/-internals/routing/lib/location/api.js +3 -3
  82. package/dist/packages/@ember/-internals/routing/lib/location/auto_location.js +5 -1
  83. package/dist/packages/@ember/-internals/routing/lib/services/router.js +7 -6
  84. package/dist/packages/@ember/-internals/routing/lib/services/routing.js +9 -6
  85. package/dist/packages/@ember/-internals/routing/lib/system/route.js +6 -9
  86. package/dist/packages/@ember/-internals/routing/lib/system/router.js +4 -2
  87. package/dist/packages/@ember/-internals/routing/lib/utils.js +15 -25
  88. package/dist/packages/@ember/-internals/runtime/lib/compare.js +4 -1
  89. package/dist/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +14 -15
  90. package/dist/packages/@ember/-internals/runtime/lib/mixins/action_handler.js +32 -44
  91. package/dist/packages/@ember/-internals/runtime/lib/mixins/array.js +1 -1
  92. package/dist/packages/@ember/-internals/runtime/lib/mixins/comparable.js +7 -22
  93. package/dist/packages/@ember/-internals/runtime/lib/mixins/container_proxy.js +34 -46
  94. package/dist/packages/@ember/-internals/runtime/lib/mixins/enumerable.js +2 -15
  95. package/dist/packages/@ember/-internals/runtime/lib/mixins/evented.js +13 -57
  96. package/dist/packages/@ember/-internals/runtime/lib/mixins/mutable_enumerable.js +2 -16
  97. package/dist/packages/@ember/-internals/runtime/lib/mixins/observable.js +64 -134
  98. package/dist/packages/@ember/-internals/runtime/lib/mixins/promise_proxy.js +28 -86
  99. package/dist/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js +59 -61
  100. package/dist/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +17 -24
  101. package/dist/packages/@ember/-internals/runtime/lib/system/array_proxy.js +59 -85
  102. package/dist/packages/@ember/-internals/runtime/lib/system/object.js +9 -2
  103. package/dist/packages/@ember/-internals/runtime/lib/system/object_proxy.js +3 -77
  104. package/dist/packages/@ember/-internals/utils/index.js +1 -1
  105. package/dist/packages/@ember/-internals/utils/types.js +1 -0
  106. package/dist/packages/@ember/-internals/views/lib/compat/attrs.js +1 -2
  107. package/dist/packages/@ember/-internals/views/lib/component_lookup.js +2 -2
  108. package/dist/packages/@ember/-internals/views/lib/mixins/action_support.js +3 -9
  109. package/dist/packages/@ember/-internals/views/lib/mixins/child_views_support.js +4 -6
  110. package/dist/packages/@ember/-internals/views/lib/mixins/class_names_support.js +13 -18
  111. package/dist/packages/@ember/-internals/views/lib/mixins/view_state_support.js +3 -2
  112. package/dist/packages/@ember/-internals/views/lib/mixins/view_support.js +57 -58
  113. package/dist/packages/@ember/-internals/views/lib/system/event_dispatcher.js +142 -120
  114. package/dist/packages/@ember/-internals/views/lib/system/utils.js +1 -1
  115. package/dist/packages/@ember/-internals/views/lib/views/states/destroying.js +1 -1
  116. package/dist/packages/@ember/-internals/views/lib/views/states/has_element.js +2 -2
  117. package/dist/packages/@ember/-internals/views/lib/views/states/in_dom.js +3 -1
  118. package/dist/packages/@ember/application/instance.js +1 -0
  119. package/dist/packages/@ember/application/lib/application.js +8 -1
  120. package/dist/packages/@ember/canary-features/index.js +2 -2
  121. package/dist/packages/@ember/engine/instance.js +1 -1
  122. package/dist/packages/@ember/engine/lib/engine-parent.js +1 -5
  123. package/dist/packages/@ember/renderer/index.js +28 -0
  124. package/dist/packages/ember/version.js +1 -1
  125. package/docs/data.json +838 -712
  126. package/package.json +4 -3
@@ -1,22 +1,14 @@
1
1
  /**
2
2
  @module ember
3
3
  */
4
- import { assert } from '@ember/debug';
5
4
  import { Mixin } from '@ember/-internals/metal';
6
- /**
7
- RegistryProxyMixin is used to provide public access to specific
8
- registry functionality.
9
-
10
- @class RegistryProxyMixin
11
- @private
12
- */
13
-
14
- export default Mixin.create({
5
+ import { assert } from '@ember/debug';
6
+ const RegistryProxyMixin = Mixin.create({
15
7
  __registry__: null,
16
8
 
17
9
  /**
18
10
  Given a fullName return the corresponding factory.
19
- @public
11
+ @public
20
12
  @method resolveRegistration
21
13
  @param {String} fullName
22
14
  @return {Function} fullName's factory
@@ -30,48 +22,48 @@ export default Mixin.create({
30
22
  Registers a factory that can be used for dependency injection (with
31
23
  `inject`) or for service lookup. Each factory is registered with
32
24
  a full name including two parts: `type:name`.
33
- A simple example:
34
- ```javascript
25
+ A simple example:
26
+ ```javascript
35
27
  import Application from '@ember/application';
36
28
  import EmberObject from '@ember/object';
37
- let App = Application.create();
38
- App.Orange = EmberObject.extend();
29
+ let App = Application.create();
30
+ App.Orange = EmberObject.extend();
39
31
  App.register('fruit:favorite', App.Orange);
40
32
  ```
41
- Ember will resolve factories from the `App` namespace automatically.
33
+ Ember will resolve factories from the `App` namespace automatically.
42
34
  For example `App.CarsController` will be discovered and returned if
43
35
  an application requests `controller:cars`.
44
- An example of registering a controller with a non-standard name:
45
- ```javascript
36
+ An example of registering a controller with a non-standard name:
37
+ ```javascript
46
38
  import Application from '@ember/application';
47
39
  import Controller from '@ember/controller';
48
- let App = Application.create();
40
+ let App = Application.create();
49
41
  let Session = Controller.extend();
50
- App.register('controller:session', Session);
51
- // The Session controller can now be treated like a normal controller,
42
+ App.register('controller:session', Session);
43
+ // The Session controller can now be treated like a normal controller,
52
44
  // despite its non-standard name.
53
45
  App.ApplicationController = Controller.extend({
54
46
  needs: ['session']
55
47
  });
56
48
  ```
57
- Registered factories are **instantiated** by having `create`
49
+ Registered factories are **instantiated** by having `create`
58
50
  called on them. Additionally they are **singletons**, each time
59
51
  they are looked up they return the same instance.
60
- Some examples modifying that default behavior:
61
- ```javascript
52
+ Some examples modifying that default behavior:
53
+ ```javascript
62
54
  import Application from '@ember/application';
63
55
  import EmberObject from '@ember/object';
64
- let App = Application.create();
65
- App.Person = EmberObject.extend();
56
+ let App = Application.create();
57
+ App.Person = EmberObject.extend();
66
58
  App.Orange = EmberObject.extend();
67
59
  App.Email = EmberObject.extend();
68
60
  App.session = EmberObject.create();
69
- App.register('model:user', App.Person, { singleton: false });
61
+ App.register('model:user', App.Person, { singleton: false });
70
62
  App.register('fruit:favorite', App.Orange);
71
63
  App.register('communication:main', App.Email, { singleton: false });
72
64
  App.register('session', App.session, { instantiate: false });
73
65
  ```
74
- @method register
66
+ @method register
75
67
  @param fullName {String} type:name (e.g., 'model:user')
76
68
  @param factory {any} (e.g., App.Person)
77
69
  @param options {Object} (optional) disable instantiation or singleton usage
@@ -81,17 +73,17 @@ export default Mixin.create({
81
73
 
82
74
  /**
83
75
  Unregister a factory.
84
- ```javascript
76
+ ```javascript
85
77
  import Application from '@ember/application';
86
78
  import EmberObject from '@ember/object';
87
- let App = Application.create();
79
+ let App = Application.create();
88
80
  let User = EmberObject.extend();
89
81
  App.register('model:user', User);
90
- App.resolveRegistration('model:user').create() instanceof User //=> true
91
- App.unregister('model:user')
82
+ App.resolveRegistration('model:user').create() instanceof User //=> true
83
+ App.unregister('model:user')
92
84
  App.resolveRegistration('model:user') === undefined //=> true
93
85
  ```
94
- @public
86
+ @public
95
87
  @method unregister
96
88
  @param {String} fullName
97
89
  */
@@ -99,7 +91,7 @@ export default Mixin.create({
99
91
 
100
92
  /**
101
93
  Check if a factory is registered.
102
- @public
94
+ @public
103
95
  @method hasRegistration
104
96
  @param {String} fullName
105
97
  @return {Boolean}
@@ -108,7 +100,7 @@ export default Mixin.create({
108
100
 
109
101
  /**
110
102
  Return a specific registered option for a particular factory.
111
- @public
103
+ @public
112
104
  @method registeredOption
113
105
  @param {String} fullName
114
106
  @param {String} optionName
@@ -118,7 +110,7 @@ export default Mixin.create({
118
110
 
119
111
  /**
120
112
  Register options for a particular factory.
121
- @public
113
+ @public
122
114
  @method registerOptions
123
115
  @param {String} fullName
124
116
  @param {Object} options
@@ -127,7 +119,7 @@ export default Mixin.create({
127
119
 
128
120
  /**
129
121
  Return registered options for a particular factory.
130
- @public
122
+ @public
131
123
  @method registeredOptions
132
124
  @param {String} fullName
133
125
  @return {Object} options
@@ -136,22 +128,22 @@ export default Mixin.create({
136
128
 
137
129
  /**
138
130
  Allow registering options for all factories of a type.
139
- ```javascript
131
+ ```javascript
140
132
  import Application from '@ember/application';
141
- let App = Application.create();
133
+ let App = Application.create();
142
134
  let appInstance = App.buildInstance();
143
- // if all of type `connection` must not be singletons
135
+ // if all of type `connection` must not be singletons
144
136
  appInstance.registerOptionsForType('connection', { singleton: false });
145
- appInstance.register('connection:twitter', TwitterConnection);
137
+ appInstance.register('connection:twitter', TwitterConnection);
146
138
  appInstance.register('connection:facebook', FacebookConnection);
147
- let twitter = appInstance.lookup('connection:twitter');
139
+ let twitter = appInstance.lookup('connection:twitter');
148
140
  let twitter2 = appInstance.lookup('connection:twitter');
149
- twitter === twitter2; // => false
150
- let facebook = appInstance.lookup('connection:facebook');
141
+ twitter === twitter2; // => false
142
+ let facebook = appInstance.lookup('connection:facebook');
151
143
  let facebook2 = appInstance.lookup('connection:facebook');
152
- facebook === facebook2; // => false
144
+ facebook === facebook2; // => false
153
145
  ```
154
- @public
146
+ @public
155
147
  @method registerOptionsForType
156
148
  @param {String} type
157
149
  @param {Object} options
@@ -160,7 +152,7 @@ export default Mixin.create({
160
152
 
161
153
  /**
162
154
  Return the registered options for all factories of a type.
163
- @public
155
+ @public
164
156
  @method registeredOptionsForType
165
157
  @param {String} type
166
158
  @return {Object} options
@@ -170,37 +162,37 @@ export default Mixin.create({
170
162
  /**
171
163
  Define a dependency injection onto a specific factory or all factories
172
164
  of a type.
173
- When Ember instantiates a controller, view, or other framework component
165
+ When Ember instantiates a controller, view, or other framework component
174
166
  it can attach a dependency to that component. This is often used to
175
167
  provide services to a set of framework components.
176
- An example of providing a session object to all controllers:
177
- ```javascript
168
+ An example of providing a session object to all controllers:
169
+ ```javascript
178
170
  import { alias } from '@ember/object/computed';
179
171
  import Application from '@ember/application';
180
172
  import Controller from '@ember/controller';
181
173
  import EmberObject from '@ember/object';
182
- let App = Application.create();
174
+ let App = Application.create();
183
175
  let Session = EmberObject.extend({ isAuthenticated: false });
184
- // A factory must be registered before it can be injected
176
+ // A factory must be registered before it can be injected
185
177
  App.register('session:main', Session);
186
- // Inject 'session:main' onto all factories of the type 'controller'
178
+ // Inject 'session:main' onto all factories of the type 'controller'
187
179
  // with the name 'session'
188
180
  App.inject('controller', 'session', 'session:main');
189
- App.IndexController = Controller.extend({
181
+ App.IndexController = Controller.extend({
190
182
  isLoggedIn: alias('session.isAuthenticated')
191
183
  });
192
184
  ```
193
- Injections can also be performed on specific factories.
194
- ```javascript
185
+ Injections can also be performed on specific factories.
186
+ ```javascript
195
187
  App.inject(<full_name or type>, <property name>, <full_name>)
196
188
  App.inject('route', 'source', 'source:main')
197
189
  App.inject('route:application', 'email', 'model:email')
198
190
  ```
199
- It is important to note that injections can only be performed on
191
+ It is important to note that injections can only be performed on
200
192
  classes that are instantiated by Ember itself. Instantiating a class
201
193
  directly (via `create` or `new`) bypasses the dependency injection
202
194
  system.
203
- @public
195
+ @public
204
196
  @method inject
205
197
  @param factoryNameOrType {String}
206
198
  @param property {String}
@@ -211,7 +203,13 @@ export default Mixin.create({
211
203
  });
212
204
 
213
205
  function registryAlias(name) {
214
- return function () {
215
- return this.__registry__[name](...arguments);
206
+ return function (...args) {
207
+ // We need this cast because `Parameters` is deferred so that it is not
208
+ // possible for TS to see it will always produce the right type. However,
209
+ // since `AnyFn` has a rest type, it is allowed. See discussion on [this
210
+ // issue](https://github.com/microsoft/TypeScript/issues/47615).
211
+ return this.__registry__[name](...args);
216
212
  };
217
- }
213
+ }
214
+
215
+ export default RegistryProxyMixin;
@@ -5,19 +5,6 @@ import { context } from '@ember/-internals/environment';
5
5
  import { get, Mixin, computed } from '@ember/-internals/metal';
6
6
  import { assert } from '@ember/debug';
7
7
  import { DEBUG } from '@glimmer/env';
8
- /**
9
- `Ember.TargetActionSupport` is a mixin that can be included in a class
10
- to add a `triggerAction` method with semantics similar to the Handlebars
11
- `{{action}}` helper. In normal Ember usage, the `{{action}}` helper is
12
- usually the best choice. This mixin is most often useful when you are
13
- doing more complex event handling in Components.
14
-
15
- @class TargetActionSupport
16
- @namespace Ember
17
- @extends Mixin
18
- @private
19
- */
20
-
21
8
  const TargetActionSupport = Mixin.create({
22
9
  target: null,
23
10
  action: null,
@@ -41,9 +28,9 @@ const TargetActionSupport = Mixin.create({
41
28
  /**
42
29
  Send an `action` with an `actionContext` to a `target`. The action, actionContext
43
30
  and target will be retrieved from properties of the object. For example:
44
- ```javascript
31
+ ```javascript
45
32
  import { alias } from '@ember/object/computed';
46
- App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
33
+ App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
47
34
  target: alias('controller'),
48
35
  action: 'save',
49
36
  actionContext: alias('context'),
@@ -53,9 +40,9 @@ const TargetActionSupport = Mixin.create({
53
40
  }
54
41
  });
55
42
  ```
56
- The `target`, `action`, and `actionContext` can be provided as properties of
43
+ The `target`, `action`, and `actionContext` can be provided as properties of
57
44
  an optional object argument to `triggerAction` as well.
58
- ```javascript
45
+ ```javascript
59
46
  App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
60
47
  click() {
61
48
  this.triggerAction({
@@ -67,12 +54,12 @@ const TargetActionSupport = Mixin.create({
67
54
  }
68
55
  });
69
56
  ```
70
- The `actionContext` defaults to the object you are mixing `TargetActionSupport` into.
57
+ The `actionContext` defaults to the object you are mixing `TargetActionSupport` into.
71
58
  But `target` and `action` must be specified either as properties or with the argument
72
59
  to `triggerAction`, or a combination:
73
- ```javascript
60
+ ```javascript
74
61
  import { alias } from '@ember/object/computed';
75
- App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
62
+ App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
76
63
  target: alias('controller'),
77
64
  click() {
78
65
  this.triggerAction({
@@ -82,7 +69,7 @@ const TargetActionSupport = Mixin.create({
82
69
  }
83
70
  });
84
71
  ```
85
- @method triggerAction
72
+ @method triggerAction
86
73
  @param opts {Object} (optional, with the optional keys action, target and/or actionContext)
87
74
  @return {Boolean} true if the action was sent successfully and did not return false
88
75
  @private
@@ -100,14 +87,16 @@ const TargetActionSupport = Mixin.create({
100
87
  actionContext = get(this, 'actionContextObject') || this;
101
88
  }
102
89
 
90
+ let context = Array.isArray(actionContext) ? actionContext : [actionContext];
91
+
103
92
  if (target && action) {
104
93
  let ret;
105
94
 
106
- if (target.send) {
107
- ret = target.send(...[action].concat(actionContext));
95
+ if (isSendable(target)) {
96
+ ret = target.send(action, ...context);
108
97
  } else {
109
98
  assert(`The action '${action}' did not exist on ${target}`, typeof target[action] === 'function');
110
- ret = target[action](...[].concat(actionContext));
99
+ ret = target[action](...context);
111
100
  }
112
101
 
113
102
  if (ret !== false) {
@@ -120,6 +109,10 @@ const TargetActionSupport = Mixin.create({
120
109
 
121
110
  });
122
111
 
112
+ function isSendable(obj) {
113
+ return obj != null && typeof obj === 'object' && typeof obj.send === 'function';
114
+ }
115
+
123
116
  function getTarget(instance) {
124
117
  let target = get(instance, 'target');
125
118
 
@@ -8,12 +8,19 @@ import { isArray, MutableArray } from '../mixins/array';
8
8
  import { assert } from '@ember/debug';
9
9
  import { setCustomTagFor } from '@glimmer/manager';
10
10
  import { combine, consumeTag, validateTag, valueForTag, tagFor } from '@glimmer/validator';
11
+
12
+ function isMutable(obj) {
13
+ return Array.isArray(obj) || typeof obj.replace === 'function';
14
+ }
15
+
11
16
  const ARRAY_OBSERVER_MAPPING = {
12
17
  willChange: '_arrangedContentArrayWillChange',
13
18
  didChange: '_arrangedContentArrayDidChange'
14
19
  };
15
20
 
16
21
  function customTagForArrayProxy(proxy, key) {
22
+ assert('[BUG] Expected a proxy', proxy instanceof ArrayProxy);
23
+
17
24
  if (key === '[]') {
18
25
  proxy._revalidate();
19
26
 
@@ -26,90 +33,53 @@ function customTagForArrayProxy(proxy, key) {
26
33
 
27
34
  return tagFor(proxy, key);
28
35
  }
29
- /**
30
- An ArrayProxy wraps any other object that implements `Array` and/or
31
- `MutableArray,` forwarding all requests. This makes it very useful for
32
- a number of binding use cases or other cases where being able to swap
33
- out the underlying array is useful.
34
-
35
- A simple example of usage:
36
-
37
- ```javascript
38
- import { A } from '@ember/array';
39
- import ArrayProxy from '@ember/array/proxy';
40
-
41
- let pets = ['dog', 'cat', 'fish'];
42
- let ap = ArrayProxy.create({ content: A(pets) });
43
-
44
- ap.get('firstObject'); // 'dog'
45
- ap.set('content', ['amoeba', 'paramecium']);
46
- ap.get('firstObject'); // 'amoeba'
47
- ```
48
-
49
- This class can also be useful as a layer to transform the contents of
50
- an array, as they are accessed. This can be done by overriding
51
- `objectAtContent`:
52
-
53
- ```javascript
54
- import { A } from '@ember/array';
55
- import ArrayProxy from '@ember/array/proxy';
56
-
57
- let pets = ['dog', 'cat', 'fish'];
58
- let ap = ArrayProxy.create({
59
- content: A(pets),
60
- objectAtContent: function(idx) {
61
- return this.get('content').objectAt(idx).toUpperCase();
62
- }
63
- });
64
-
65
- ap.get('firstObject'); // . 'DOG'
66
- ```
67
-
68
- When overriding this class, it is important to place the call to
69
- `_super` *after* setting `content` so the internal observers have
70
- a chance to fire properly:
71
36
 
72
- ```javascript
73
- import { A } from '@ember/array';
74
- import ArrayProxy from '@ember/array/proxy';
75
-
76
- export default ArrayProxy.extend({
77
- init() {
78
- this.set('content', A(['dog', 'cat', 'fish']));
79
- this._super(...arguments);
80
- }
81
- });
82
- ```
83
-
84
- @class ArrayProxy
85
- @extends EmberObject
86
- @uses MutableArray
87
- @public
88
- */
89
-
90
-
91
- export default class ArrayProxy extends EmberObject {
92
- init() {
93
- super.init(...arguments);
37
+ class ArrayProxy extends EmberObject {
38
+ constructor() {
39
+ super(...arguments);
94
40
  /*
95
41
  `this._objectsDirtyIndex` determines which indexes in the `this._objects`
96
42
  cache are dirty.
97
- If `this._objectsDirtyIndex === -1` then no indexes are dirty.
43
+ If `this._objectsDirtyIndex === -1` then no indexes are dirty.
98
44
  Otherwise, an index `i` is dirty if `i >= this._objectsDirtyIndex`.
99
- Calling `objectAt` with a dirty index will cause the `this._objects`
45
+ Calling `objectAt` with a dirty index will cause the `this._objects`
100
46
  cache to be recomputed.
101
47
  */
102
48
 
49
+ /** @internal */
50
+
103
51
  this._objectsDirtyIndex = 0;
52
+ /** @internal */
53
+
104
54
  this._objects = null;
55
+ /** @internal */
56
+
105
57
  this._lengthDirty = true;
58
+ /** @internal */
59
+
106
60
  this._length = 0;
61
+ /** @internal */
62
+
107
63
  this._arrangedContent = null;
64
+ /** @internal */
65
+
108
66
  this._arrangedContentIsUpdating = false;
67
+ /** @internal */
68
+
109
69
  this._arrangedContentTag = null;
70
+ /** @internal */
71
+
110
72
  this._arrangedContentRevision = null;
73
+ /** @internal */
74
+
111
75
  this._lengthTag = null;
76
+ /** @internal */
77
+
112
78
  this._arrTag = null;
79
+ }
80
+
81
+ init(props) {
82
+ super.init(props);
113
83
  setCustomTagFor(this, customTagForArrayProxy);
114
84
  }
115
85
 
@@ -120,20 +90,12 @@ export default class ArrayProxy extends EmberObject {
120
90
  willDestroy() {
121
91
  this._removeArrangedContentArrayObserver();
122
92
  }
123
- /**
124
- The content array. Must be an object that implements `Array` and/or
125
- `MutableArray.`
126
- @property content
127
- @type EmberArray
128
- @public
129
- */
130
-
131
93
  /**
132
94
  Should actually retrieve the object at the specified index from the
133
95
  content. You can override this method in subclasses to transform the
134
96
  content item to something new.
135
- This method will only be called if content is non-`null`.
136
- @method objectAtContent
97
+ This method will only be called if content is non-`null`.
98
+ @method objectAtContent
137
99
  @param {Number} idx The index to retrieve.
138
100
  @return {Object} the value or undefined if none found
139
101
  @public
@@ -141,7 +103,9 @@ export default class ArrayProxy extends EmberObject {
141
103
 
142
104
 
143
105
  objectAtContent(idx) {
144
- return objectAt(get(this, 'arrangedContent'), idx);
106
+ let arrangedContent = get(this, 'arrangedContent');
107
+ assert('[BUG] Called objectAtContent without content', arrangedContent);
108
+ return objectAt(arrangedContent, idx);
145
109
  } // See additional docs for `replace` from `MutableArray`:
146
110
  // https://api.emberjs.com/ember/release/classes/MutableArray/methods/replace?anchor=replace
147
111
 
@@ -154,19 +118,21 @@ export default class ArrayProxy extends EmberObject {
154
118
  Should actually replace the specified objects on the content array.
155
119
  You can override this method in subclasses to transform the content item
156
120
  into something new.
157
- This method will only be called if content is non-`null`.
158
- @method replaceContent
121
+ This method will only be called if content is non-`null`.
122
+ @method replaceContent
159
123
  @param {Number} idx The starting index
160
124
  @param {Number} amt The number of items to remove from the content.
161
- @param {EmberArray} objects Optional array of objects to insert or null if no
162
- objects.
125
+ @param {EmberArray} objects Optional array of objects to insert.
163
126
  @return {void}
164
127
  @public
165
128
  */
166
129
 
167
130
 
168
131
  replaceContent(idx, amt, objects) {
169
- get(this, 'content').replace(idx, amt, objects);
132
+ let content = get(this, 'content');
133
+ assert('[BUG] Called objectAtContent without content', content);
134
+ assert('Mutating a non-mutable array is not allowed', isMutable(content));
135
+ content.replace(idx, amt, objects);
170
136
  } // Overriding objectAt is not supported.
171
137
 
172
138
 
@@ -184,6 +150,9 @@ export default class ArrayProxy extends EmberObject {
184
150
  let length = this._objects.length = get(arrangedContent, 'length');
185
151
 
186
152
  for (let i = this._objectsDirtyIndex; i < length; i++) {
153
+ // SAFETY: This is expected to only ever return an instance of T. In other words, there should
154
+ // be no gaps in the array. Unfortunately, we can't actually assert for it since T could include
155
+ // any types, including null or undefined.
187
156
  this._objects[i] = this.objectAtContent(i);
188
157
  }
189
158
  } else {
@@ -206,6 +175,7 @@ export default class ArrayProxy extends EmberObject {
206
175
  this._lengthDirty = false;
207
176
  }
208
177
 
178
+ assert('[BUG] _lengthTag is not set', this._lengthTag);
209
179
  consumeTag(this._lengthTag);
210
180
  return this._length;
211
181
  }
@@ -225,6 +195,7 @@ export default class ArrayProxy extends EmberObject {
225
195
  let content = get(this, 'content');
226
196
 
227
197
  if (content) {
198
+ assert('Mutating a non-mutable array is not allowed', isMutable(content));
228
199
  replace(content, value, removedCount, added);
229
200
 
230
201
  this._invalidate();
@@ -248,6 +219,7 @@ export default class ArrayProxy extends EmberObject {
248
219
 
249
220
  _addArrangedContentArrayObserver(arrangedContent) {
250
221
  if (arrangedContent && !arrangedContent.isDestroyed) {
222
+ // @ts-expect-error This check is still good for ensuring correctness
251
223
  assert("Can't set ArrayProxy's content to itself", arrangedContent !== this);
252
224
  assert(`ArrayProxy expects an Array or ArrayProxy, but you passed ${typeof arrangedContent}`, isArray(arrangedContent) || arrangedContent.isDestroyed);
253
225
  addArrayObserver(arrangedContent, this, ARRAY_OBSERVER_MAPPING);
@@ -263,7 +235,7 @@ export default class ArrayProxy extends EmberObject {
263
235
 
264
236
  _arrangedContentArrayWillChange() {}
265
237
 
266
- _arrangedContentArrayDidChange(proxy, idx, removedCnt, addedCnt) {
238
+ _arrangedContentArrayDidChange(_proxy, idx, removedCnt, addedCnt) {
267
239
  arrayContentWillChange(this, idx, removedCnt, addedCnt);
268
240
  let dirtyIndex = idx;
269
241
 
@@ -316,13 +288,15 @@ export default class ArrayProxy extends EmberObject {
316
288
  }
317
289
 
318
290
  }
291
+
319
292
  ArrayProxy.reopen(MutableArray, {
320
293
  /**
321
294
  The array that the proxy pretends to be. In the default `ArrayProxy`
322
295
  implementation, this and `content` are the same. Subclasses of `ArrayProxy`
323
296
  can override this property to provide things like sorting and filtering.
324
- @property arrangedContent
297
+ @property arrangedContent
325
298
  @public
326
299
  */
327
300
  arrangedContent: alias('content')
328
- });
301
+ });
302
+ export default ArrayProxy;
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  @module @ember/object
3
3
  */
4
+ var _a;
5
+
4
6
  import { getFactoryFor } from '@ember/-internals/container';
5
7
  import { symbol } from '@ember/-internals/utils';
6
8
  import { addListener } from '@ember/-internals/metal';
@@ -21,15 +23,20 @@ export default EmberObject;
21
23
  let FrameworkObject = class FrameworkObject extends EmberObject {};
22
24
 
23
25
  if (DEBUG) {
24
- let INIT_WAS_CALLED = symbol('INIT_WAS_CALLED');
26
+ const INIT_WAS_CALLED = Symbol('INIT_WAS_CALLED');
25
27
  let ASSERT_INIT_WAS_CALLED = symbol('ASSERT_INIT_WAS_CALLED');
26
28
  FrameworkObject = class DebugFrameworkObject extends EmberObject {
29
+ constructor() {
30
+ super(...arguments);
31
+ this[_a] = false;
32
+ }
33
+
27
34
  init(properties) {
28
35
  super.init(properties);
29
36
  this[INIT_WAS_CALLED] = true;
30
37
  }
31
38
 
32
- [ASSERT_INIT_WAS_CALLED]() {
39
+ [(_a = INIT_WAS_CALLED, ASSERT_INIT_WAS_CALLED)]() {
33
40
  assert(`You must call \`super.init(...arguments);\` or \`this._super(...arguments)\` when overriding \`init\` on a framework object. Please update ${this} to call \`super.init(...arguments);\` from \`init\` when using native classes or \`this._super(...arguments)\` when using \`EmberObject.extend()\`.`, this[INIT_WAS_CALLED]);
34
41
  }
35
42