ember-source 4.9.0-alpha.2 → 4.9.0-alpha.4
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.
- package/CHANGELOG.md +9 -0
- package/build-metadata.json +3 -3
- package/dist/ember-template-compiler.js +9 -4
- package/dist/ember-template-compiler.map +1 -1
- package/dist/ember-testing.js +1 -1
- package/dist/ember-testing.map +1 -1
- package/dist/ember.debug.js +29 -1428
- package/dist/ember.debug.map +1 -1
- package/dist/header/license.js +1 -1
- package/dist/packages/@ember/-internals/container/index.js +1 -1
- package/dist/packages/@ember/-internals/glimmer/index.js +5 -5
- package/dist/packages/@ember/-internals/meta/lib/meta.js +13 -13
- package/dist/packages/@ember/array/index.js +0 -909
- package/dist/packages/@ember/array/proxy.js +0 -31
- package/dist/packages/@ember/controller/index.js +0 -156
- package/dist/packages/@ember/debug/data-adapter.js +8 -2
- package/dist/packages/@ember/object/observable.js +0 -228
- package/dist/packages/@ember/object/promise-proxy-mixin.js +0 -80
- package/dist/packages/@ember/routing/route.js +1 -1
- package/dist/packages/ember/version.js +1 -1
- package/docs/data.json +262 -383
- package/package.json +14 -10
- package/types/preview/@ember/routing/route.d.ts +3 -4
- package/types/stable/index.d.ts +12 -0
|
@@ -185,65 +185,10 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
185
185
|
setEmberArray(this);
|
|
186
186
|
},
|
|
187
187
|
|
|
188
|
-
/**
|
|
189
|
-
__Required.__ You must implement this method to apply this mixin.
|
|
190
|
-
Your array must support the `length` property. Your replace methods should
|
|
191
|
-
set this property whenever it changes.
|
|
192
|
-
@property {Number} length
|
|
193
|
-
@public
|
|
194
|
-
*/
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
Returns the object at the given `index`. If the given `index` is negative
|
|
198
|
-
or is greater or equal than the array length, returns `undefined`.
|
|
199
|
-
This is one of the primitives you must implement to support `EmberArray`.
|
|
200
|
-
If your object supports retrieving the value of an array item using `get()`
|
|
201
|
-
(i.e. `myArray.get(0)`), then you do not need to implement this method
|
|
202
|
-
yourself.
|
|
203
|
-
```javascript
|
|
204
|
-
let arr = ['a', 'b', 'c', 'd'];
|
|
205
|
-
arr.objectAt(0); // 'a'
|
|
206
|
-
arr.objectAt(3); // 'd'
|
|
207
|
-
arr.objectAt(-1); // undefined
|
|
208
|
-
arr.objectAt(4); // undefined
|
|
209
|
-
arr.objectAt(5); // undefined
|
|
210
|
-
```
|
|
211
|
-
@method objectAt
|
|
212
|
-
@param {Number} idx The index of the item to return.
|
|
213
|
-
@return {*} item at index or undefined
|
|
214
|
-
@public
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
This returns the objects at the specified indexes, using `objectAt`.
|
|
219
|
-
```javascript
|
|
220
|
-
let arr = ['a', 'b', 'c', 'd'];
|
|
221
|
-
arr.objectsAt([0, 1, 2]); // ['a', 'b', 'c']
|
|
222
|
-
arr.objectsAt([2, 3, 4]); // ['c', 'd', undefined]
|
|
223
|
-
```
|
|
224
|
-
@method objectsAt
|
|
225
|
-
@param {Array} indexes An array of indexes of items to return.
|
|
226
|
-
@return {Array}
|
|
227
|
-
@public
|
|
228
|
-
*/
|
|
229
188
|
objectsAt(indexes) {
|
|
230
189
|
return indexes.map(idx => objectAt(this, idx));
|
|
231
190
|
},
|
|
232
191
|
|
|
233
|
-
/**
|
|
234
|
-
This is the handler for the special array content property. If you get
|
|
235
|
-
this property, it will return this. If you set this property to a new
|
|
236
|
-
array, it will replace the current content.
|
|
237
|
-
```javascript
|
|
238
|
-
let peopleToMoon = ['Armstrong', 'Aldrin'];
|
|
239
|
-
peopleToMoon.get('[]'); // ['Armstrong', 'Aldrin']
|
|
240
|
-
peopleToMoon.set('[]', ['Collins']); // ['Collins']
|
|
241
|
-
peopleToMoon.get('[]'); // ['Collins']
|
|
242
|
-
```
|
|
243
|
-
@property []
|
|
244
|
-
@return this
|
|
245
|
-
@public
|
|
246
|
-
*/
|
|
247
192
|
'[]': nonEnumerableComputed({
|
|
248
193
|
get() {
|
|
249
194
|
return this;
|
|
@@ -255,55 +200,14 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
255
200
|
}
|
|
256
201
|
|
|
257
202
|
}),
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
The first object in the array, or `undefined` if the array is empty.
|
|
261
|
-
```javascript
|
|
262
|
-
let vowels = ['a', 'e', 'i', 'o', 'u'];
|
|
263
|
-
vowels.firstObject; // 'a'
|
|
264
|
-
vowels.shiftObject();
|
|
265
|
-
vowels.firstObject; // 'e'
|
|
266
|
-
vowels.reverseObjects();
|
|
267
|
-
vowels.firstObject; // 'u'
|
|
268
|
-
vowels.clear();
|
|
269
|
-
vowels.firstObject; // undefined
|
|
270
|
-
```
|
|
271
|
-
@property firstObject
|
|
272
|
-
@return {Object | undefined} The first object in the array
|
|
273
|
-
@public
|
|
274
|
-
*/
|
|
275
203
|
firstObject: nonEnumerableComputed(function () {
|
|
276
204
|
return objectAt(this, 0);
|
|
277
205
|
}).readOnly(),
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
The last object in the array, or `undefined` if the array is empty.
|
|
281
|
-
@property lastObject
|
|
282
|
-
@return {Object | undefined} The last object in the array
|
|
283
|
-
@public
|
|
284
|
-
*/
|
|
285
206
|
lastObject: nonEnumerableComputed(function () {
|
|
286
207
|
return objectAt(this, this.length - 1);
|
|
287
208
|
}).readOnly(),
|
|
288
209
|
|
|
289
210
|
// Add any extra methods to EmberArray that are native to the built-in Array.
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
Returns a new array that is a slice of the receiver. This implementation
|
|
293
|
-
uses the observable array methods to retrieve the objects for the new
|
|
294
|
-
slice.
|
|
295
|
-
```javascript
|
|
296
|
-
let arr = ['red', 'green', 'blue'];
|
|
297
|
-
arr.slice(0); // ['red', 'green', 'blue']
|
|
298
|
-
arr.slice(0, 2); // ['red', 'green']
|
|
299
|
-
arr.slice(1, 100); // ['green', 'blue']
|
|
300
|
-
```
|
|
301
|
-
@method slice
|
|
302
|
-
@param {Number} beginIndex (Optional) index to begin slicing from.
|
|
303
|
-
@param {Number} endIndex (Optional) index to end the slice at (but not included).
|
|
304
|
-
@return {Array} New array with specified slice
|
|
305
|
-
@public
|
|
306
|
-
*/
|
|
307
211
|
slice(beginIndex = 0, endIndex) {
|
|
308
212
|
let ret = A();
|
|
309
213
|
let length = this.length;
|
|
@@ -329,70 +233,10 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
329
233
|
return ret;
|
|
330
234
|
},
|
|
331
235
|
|
|
332
|
-
/**
|
|
333
|
-
Used to determine the passed object's first occurrence in the array.
|
|
334
|
-
Returns the index if found, -1 if no match is found.
|
|
335
|
-
The optional `startAt` argument can be used to pass a starting
|
|
336
|
-
index to search from, effectively slicing the searchable portion
|
|
337
|
-
of the array. If it's negative it will add the array length to
|
|
338
|
-
the startAt value passed in as the index to search from. If less
|
|
339
|
-
than or equal to `-1 * array.length` the entire array is searched.
|
|
340
|
-
```javascript
|
|
341
|
-
let arr = ['a', 'b', 'c', 'd', 'a'];
|
|
342
|
-
arr.indexOf('a'); // 0
|
|
343
|
-
arr.indexOf('z'); // -1
|
|
344
|
-
arr.indexOf('a', 2); // 4
|
|
345
|
-
arr.indexOf('a', -1); // 4, equivalent to indexOf('a', 4)
|
|
346
|
-
arr.indexOf('a', -100); // 0, searches entire array
|
|
347
|
-
arr.indexOf('b', 3); // -1
|
|
348
|
-
arr.indexOf('a', 100); // -1
|
|
349
|
-
let people = [{ name: 'Zoey' }, { name: 'Bob' }]
|
|
350
|
-
let newPerson = { name: 'Tom' };
|
|
351
|
-
people = [newPerson, ...people, newPerson];
|
|
352
|
-
people.indexOf(newPerson); // 0
|
|
353
|
-
people.indexOf(newPerson, 1); // 3
|
|
354
|
-
people.indexOf(newPerson, -4); // 0
|
|
355
|
-
people.indexOf(newPerson, 10); // -1
|
|
356
|
-
```
|
|
357
|
-
@method indexOf
|
|
358
|
-
@param {Object} object the item to search for
|
|
359
|
-
@param {Number} startAt optional starting location to search, default 0
|
|
360
|
-
@return {Number} index or -1 if not found
|
|
361
|
-
@public
|
|
362
|
-
*/
|
|
363
236
|
indexOf(object, startAt) {
|
|
364
237
|
return indexOf(this, object, startAt, false);
|
|
365
238
|
},
|
|
366
239
|
|
|
367
|
-
/**
|
|
368
|
-
Returns the index of the given `object`'s last occurrence.
|
|
369
|
-
- If no `startAt` argument is given, the search starts from
|
|
370
|
-
the last position.
|
|
371
|
-
- If it's greater than or equal to the length of the array,
|
|
372
|
-
the search starts from the last position.
|
|
373
|
-
- If it's negative, it is taken as the offset from the end
|
|
374
|
-
of the array i.e. `startAt + array.length`.
|
|
375
|
-
- If it's any other positive number, will search backwards
|
|
376
|
-
from that index of the array.
|
|
377
|
-
Returns -1 if no match is found.
|
|
378
|
-
```javascript
|
|
379
|
-
let arr = ['a', 'b', 'c', 'd', 'a'];
|
|
380
|
-
arr.lastIndexOf('a'); // 4
|
|
381
|
-
arr.lastIndexOf('z'); // -1
|
|
382
|
-
arr.lastIndexOf('a', 2); // 0
|
|
383
|
-
arr.lastIndexOf('a', -1); // 4
|
|
384
|
-
arr.lastIndexOf('a', -3); // 0
|
|
385
|
-
arr.lastIndexOf('b', 3); // 1
|
|
386
|
-
arr.lastIndexOf('a', 100); // 4
|
|
387
|
-
```
|
|
388
|
-
@method lastIndexOf
|
|
389
|
-
@param {Object} object the item to search for
|
|
390
|
-
@param {Number} startAt optional starting location to search from
|
|
391
|
-
backwards, defaults to `(array.length - 1)`
|
|
392
|
-
@return {Number} The last index of the `object` in the array or -1
|
|
393
|
-
if not found
|
|
394
|
-
@public
|
|
395
|
-
*/
|
|
396
240
|
lastIndexOf(object, startAt) {
|
|
397
241
|
let len = this.length;
|
|
398
242
|
|
|
@@ -413,44 +257,6 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
413
257
|
return -1;
|
|
414
258
|
},
|
|
415
259
|
|
|
416
|
-
/**
|
|
417
|
-
Iterates through the array, calling the passed function on each
|
|
418
|
-
item. This method corresponds to the `forEach()` method defined in
|
|
419
|
-
JavaScript 1.6.
|
|
420
|
-
The callback method you provide should have the following signature (all
|
|
421
|
-
parameters are optional):
|
|
422
|
-
```javascript
|
|
423
|
-
function(item, index, array);
|
|
424
|
-
```
|
|
425
|
-
- `item` is the current item in the iteration.
|
|
426
|
-
- `index` is the current index in the iteration.
|
|
427
|
-
- `array` is the array itself.
|
|
428
|
-
Note that in addition to a callback, you can also pass an optional target
|
|
429
|
-
object that will be set as `this` on the context. This is a good way
|
|
430
|
-
to give your iterator function access to the current object.
|
|
431
|
-
Example Usage:
|
|
432
|
-
```javascript
|
|
433
|
-
let foods = [
|
|
434
|
-
{ name: 'apple', eaten: false },
|
|
435
|
-
{ name: 'banana', eaten: false },
|
|
436
|
-
{ name: 'carrot', eaten: false }
|
|
437
|
-
];
|
|
438
|
-
foods.forEach((food) => food.eaten = true);
|
|
439
|
-
let output = '';
|
|
440
|
-
foods.forEach((item, index, array) =>
|
|
441
|
-
output += `${index + 1}/${array.length} ${item.name}\n`;
|
|
442
|
-
);
|
|
443
|
-
console.log(output);
|
|
444
|
-
// 1/3 apple
|
|
445
|
-
// 2/3 banana
|
|
446
|
-
// 3/3 carrot
|
|
447
|
-
```
|
|
448
|
-
@method forEach
|
|
449
|
-
@param {Function} callback The callback to execute
|
|
450
|
-
@param {Object} [target] The target object to use
|
|
451
|
-
@return {Object} receiver
|
|
452
|
-
@public
|
|
453
|
-
*/
|
|
454
260
|
forEach(callback, target = null) {
|
|
455
261
|
assert('`forEach` expects a function as first argument.', typeof callback === 'function');
|
|
456
262
|
let length = this.length;
|
|
@@ -463,70 +269,12 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
463
269
|
return this;
|
|
464
270
|
},
|
|
465
271
|
|
|
466
|
-
/**
|
|
467
|
-
Alias for `mapBy`.
|
|
468
|
-
Returns the value of the named
|
|
469
|
-
property on all items in the enumeration.
|
|
470
|
-
```javascript
|
|
471
|
-
let people = [{name: 'Joe'}, {name: 'Matt'}];
|
|
472
|
-
people.getEach('name');
|
|
473
|
-
// ['Joe', 'Matt'];
|
|
474
|
-
people.getEach('nonexistentProperty');
|
|
475
|
-
// [undefined, undefined];
|
|
476
|
-
```
|
|
477
|
-
@method getEach
|
|
478
|
-
@param {String} key name of the property
|
|
479
|
-
@return {Array} The mapped array.
|
|
480
|
-
@public
|
|
481
|
-
*/
|
|
482
272
|
getEach: mapBy,
|
|
483
273
|
|
|
484
|
-
/**
|
|
485
|
-
Sets the value on the named property for each member. This is more
|
|
486
|
-
ergonomic than using other methods defined on this helper. If the object
|
|
487
|
-
implements Observable, the value will be changed to `set(),` otherwise
|
|
488
|
-
it will be set directly. `null` objects are skipped.
|
|
489
|
-
```javascript
|
|
490
|
-
let people = [{name: 'Joe'}, {name: 'Matt'}];
|
|
491
|
-
people.setEach('zipCode', '10011');
|
|
492
|
-
// [{name: 'Joe', zipCode: '10011'}, {name: 'Matt', zipCode: '10011'}];
|
|
493
|
-
```
|
|
494
|
-
@method setEach
|
|
495
|
-
@param {String} key The key to set
|
|
496
|
-
@param {Object} value The object to set
|
|
497
|
-
@return {Object} receiver
|
|
498
|
-
@public
|
|
499
|
-
*/
|
|
500
274
|
setEach(key, value) {
|
|
501
275
|
return this.forEach(item => set(item, key, value));
|
|
502
276
|
},
|
|
503
277
|
|
|
504
|
-
/**
|
|
505
|
-
Maps all of the items in the enumeration to another value, returning
|
|
506
|
-
a new array. This method corresponds to `map()` defined in JavaScript 1.6.
|
|
507
|
-
The callback method you provide should have the following signature (all
|
|
508
|
-
parameters are optional):
|
|
509
|
-
```javascript
|
|
510
|
-
function(item, index, array);
|
|
511
|
-
let arr = [1, 2, 3, 4, 5, 6];
|
|
512
|
-
arr.map(element => element * element);
|
|
513
|
-
// [1, 4, 9, 16, 25, 36];
|
|
514
|
-
arr.map((element, index) => element + index);
|
|
515
|
-
// [1, 3, 5, 7, 9, 11];
|
|
516
|
-
```
|
|
517
|
-
- `item` is the current item in the iteration.
|
|
518
|
-
- `index` is the current index in the iteration.
|
|
519
|
-
- `array` is the array itself.
|
|
520
|
-
It should return the mapped value.
|
|
521
|
-
Note that in addition to a callback, you can also pass an optional target
|
|
522
|
-
object that will be set as `this` on the context. This is a good way
|
|
523
|
-
to give your iterator function access to the current object.
|
|
524
|
-
@method map
|
|
525
|
-
@param {Function} callback The callback to execute
|
|
526
|
-
@param {Object} [target] The target object to use
|
|
527
|
-
@return {Array} The mapped array.
|
|
528
|
-
@public
|
|
529
|
-
*/
|
|
530
278
|
map(callback, target = null) {
|
|
531
279
|
assert('`map` expects a function as first argument.', typeof callback === 'function');
|
|
532
280
|
let ret = A();
|
|
@@ -534,67 +282,8 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
534
282
|
return ret;
|
|
535
283
|
},
|
|
536
284
|
|
|
537
|
-
/**
|
|
538
|
-
Similar to map, this specialized function returns the value of the named
|
|
539
|
-
property on all items in the enumeration.
|
|
540
|
-
```javascript
|
|
541
|
-
let people = [{name: 'Joe'}, {name: 'Matt'}];
|
|
542
|
-
people.mapBy('name');
|
|
543
|
-
// ['Joe', 'Matt'];
|
|
544
|
-
people.mapBy('unknownProperty');
|
|
545
|
-
// [undefined, undefined];
|
|
546
|
-
```
|
|
547
|
-
@method mapBy
|
|
548
|
-
@param {String} key name of the property
|
|
549
|
-
@return {Array} The mapped array.
|
|
550
|
-
@public
|
|
551
|
-
*/
|
|
552
285
|
mapBy,
|
|
553
286
|
|
|
554
|
-
/**
|
|
555
|
-
Returns a new array with all of the items in the enumeration that the provided
|
|
556
|
-
callback function returns true for. This method corresponds to [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).
|
|
557
|
-
The callback method should have the following signature:
|
|
558
|
-
```javascript
|
|
559
|
-
function(item, index, array);
|
|
560
|
-
```
|
|
561
|
-
- `item` is the current item in the iteration.
|
|
562
|
-
- `index` is the current index in the iteration.
|
|
563
|
-
- `array` is the array itself.
|
|
564
|
-
All parameters are optional. The function should return `true` to include the item
|
|
565
|
-
in the results, and `false` otherwise.
|
|
566
|
-
Example:
|
|
567
|
-
```javascript
|
|
568
|
-
function isAdult(person) {
|
|
569
|
-
return person.age > 18;
|
|
570
|
-
};
|
|
571
|
-
let people = Ember.A([{ name: 'John', age: 14 }, { name: 'Joan', age: 45 }]);
|
|
572
|
-
people.filter(isAdult); // returns [{ name: 'Joan', age: 45 }];
|
|
573
|
-
```
|
|
574
|
-
Note that in addition to a callback, you can pass an optional target object
|
|
575
|
-
that will be set as `this` on the context. This is a good way to give your
|
|
576
|
-
iterator function access to the current object. For example:
|
|
577
|
-
```javascript
|
|
578
|
-
function isAdultAndEngineer(person) {
|
|
579
|
-
return person.age > 18 && this.engineering;
|
|
580
|
-
}
|
|
581
|
-
class AdultsCollection {
|
|
582
|
-
engineering = false;
|
|
583
|
-
constructor(opts = {}) {
|
|
584
|
-
super(...arguments);
|
|
585
|
-
this.engineering = opts.engineering;
|
|
586
|
-
this.people = Ember.A([{ name: 'John', age: 14 }, { name: 'Joan', age: 45 }]);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
let collection = new AdultsCollection({ engineering: true });
|
|
590
|
-
collection.people.filter(isAdultAndEngineer, { target: collection });
|
|
591
|
-
```
|
|
592
|
-
@method filter
|
|
593
|
-
@param {Function} callback The callback to execute
|
|
594
|
-
@param {Object} [target] The target object to use
|
|
595
|
-
@return {Array} A filtered array.
|
|
596
|
-
@public
|
|
597
|
-
*/
|
|
598
287
|
filter(callback, target = null) {
|
|
599
288
|
assert('`filter` expects a function as first argument.', typeof callback === 'function');
|
|
600
289
|
let ret = A();
|
|
@@ -606,38 +295,6 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
606
295
|
return ret;
|
|
607
296
|
},
|
|
608
297
|
|
|
609
|
-
/**
|
|
610
|
-
Returns an array with all of the items in the enumeration where the passed
|
|
611
|
-
function returns false. This method is the inverse of filter().
|
|
612
|
-
The callback method you provide should have the following signature (all
|
|
613
|
-
parameters are optional):
|
|
614
|
-
```javascript
|
|
615
|
-
function(item, index, array);
|
|
616
|
-
```
|
|
617
|
-
- *item* is the current item in the iteration.
|
|
618
|
-
- *index* is the current index in the iteration
|
|
619
|
-
- *array* is the array itself.
|
|
620
|
-
It should return a falsey value to include the item in the results.
|
|
621
|
-
Note that in addition to a callback, you can also pass an optional target
|
|
622
|
-
object that will be set as "this" on the context. This is a good way
|
|
623
|
-
to give your iterator function access to the current object.
|
|
624
|
-
Example Usage:
|
|
625
|
-
```javascript
|
|
626
|
-
const food = [
|
|
627
|
-
{ food: 'apple', isFruit: true },
|
|
628
|
-
{ food: 'bread', isFruit: false },
|
|
629
|
-
{ food: 'banana', isFruit: true }
|
|
630
|
-
];
|
|
631
|
-
const nonFruits = food.reject(function(thing) {
|
|
632
|
-
return thing.isFruit;
|
|
633
|
-
}); // [{food: 'bread', isFruit: false}]
|
|
634
|
-
```
|
|
635
|
-
@method reject
|
|
636
|
-
@param {Function} callback The callback to execute
|
|
637
|
-
@param {Object} [target] The target object to use
|
|
638
|
-
@return {Array} A rejected array.
|
|
639
|
-
@public
|
|
640
|
-
*/
|
|
641
298
|
reject(callback, target = null) {
|
|
642
299
|
assert('`reject` expects a function as first argument.', typeof callback === 'function');
|
|
643
300
|
return this.filter(function () {
|
|
@@ -646,294 +303,49 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
646
303
|
});
|
|
647
304
|
},
|
|
648
305
|
|
|
649
|
-
/**
|
|
650
|
-
Filters the array by the property and an optional value. If a value is given, it returns
|
|
651
|
-
the items that have said value for the property. If not, it returns all the items that
|
|
652
|
-
have a truthy value for the property.
|
|
653
|
-
Example Usage:
|
|
654
|
-
```javascript
|
|
655
|
-
let things = Ember.A([{ food: 'apple', isFruit: true }, { food: 'beans', isFruit: false }]);
|
|
656
|
-
things.filterBy('food', 'beans'); // [{ food: 'beans', isFruit: false }]
|
|
657
|
-
things.filterBy('isFruit'); // [{ food: 'apple', isFruit: true }]
|
|
658
|
-
```
|
|
659
|
-
@method filterBy
|
|
660
|
-
@param {String} key the property to test
|
|
661
|
-
@param {*} [value] optional value to test against.
|
|
662
|
-
@return {Array} filtered array
|
|
663
|
-
@public
|
|
664
|
-
*/
|
|
665
306
|
filterBy() {
|
|
666
307
|
// @ts-expect-error TS doesn't like the ...arguments spread here.
|
|
667
308
|
return this.filter(iter(...arguments));
|
|
668
309
|
},
|
|
669
310
|
|
|
670
|
-
/**
|
|
671
|
-
Returns an array with the items that do not have truthy values for the provided key.
|
|
672
|
-
You can pass an optional second argument with a target value to reject for the key.
|
|
673
|
-
Otherwise this will reject objects where the provided property evaluates to false.
|
|
674
|
-
Example Usage:
|
|
675
|
-
```javascript
|
|
676
|
-
let food = [
|
|
677
|
-
{ name: "apple", isFruit: true },
|
|
678
|
-
{ name: "carrot", isFruit: false },
|
|
679
|
-
{ name: "bread", isFruit: false },
|
|
680
|
-
];
|
|
681
|
-
food.rejectBy('isFruit'); // [{ name: "carrot", isFruit: false }, { name: "bread", isFruit: false }]
|
|
682
|
-
food.rejectBy('name', 'carrot'); // [{ name: "apple", isFruit: true }}, { name: "bread", isFruit: false }]
|
|
683
|
-
```
|
|
684
|
-
@method rejectBy
|
|
685
|
-
@param {String} key the property to test
|
|
686
|
-
@param {*} [value] optional value to test against.
|
|
687
|
-
@return {Array} rejected array
|
|
688
|
-
@public
|
|
689
|
-
*/
|
|
690
311
|
rejectBy() {
|
|
691
312
|
// @ts-expect-error TS doesn't like the ...arguments spread here.
|
|
692
313
|
return this.reject(iter(...arguments));
|
|
693
314
|
},
|
|
694
315
|
|
|
695
|
-
/**
|
|
696
|
-
Returns the first item in the array for which the callback returns true.
|
|
697
|
-
This method is similar to the `find()` method defined in ECMAScript 2015.
|
|
698
|
-
The callback method you provide should have the following signature (all
|
|
699
|
-
parameters are optional):
|
|
700
|
-
```javascript
|
|
701
|
-
function(item, index, array);
|
|
702
|
-
```
|
|
703
|
-
- `item` is the current item in the iteration.
|
|
704
|
-
- `index` is the current index in the iteration.
|
|
705
|
-
- `array` is the array itself.
|
|
706
|
-
It should return the `true` to include the item in the results, `false`
|
|
707
|
-
otherwise.
|
|
708
|
-
Note that in addition to a callback, you can also pass an optional target
|
|
709
|
-
object that will be set as `this` on the context. This is a good way
|
|
710
|
-
to give your iterator function access to the current object.
|
|
711
|
-
Example Usage:
|
|
712
|
-
```javascript
|
|
713
|
-
let users = [
|
|
714
|
-
{ id: 1, name: 'Yehuda' },
|
|
715
|
-
{ id: 2, name: 'Tom' },
|
|
716
|
-
{ id: 3, name: 'Melanie' },
|
|
717
|
-
{ id: 4, name: 'Leah' }
|
|
718
|
-
];
|
|
719
|
-
users.find((user) => user.name == 'Tom'); // [{ id: 2, name: 'Tom' }]
|
|
720
|
-
users.find(({ id }) => id == 3); // [{ id: 3, name: 'Melanie' }]
|
|
721
|
-
```
|
|
722
|
-
@method find
|
|
723
|
-
@param {Function} callback The callback to execute
|
|
724
|
-
@param {Object} [target] The target object to use
|
|
725
|
-
@return {Object} Found item or `undefined`.
|
|
726
|
-
@public
|
|
727
|
-
*/
|
|
728
316
|
find(callback, target = null) {
|
|
729
317
|
assert('`find` expects a function as first argument.', typeof callback === 'function');
|
|
730
318
|
return find(this, callback, target);
|
|
731
319
|
},
|
|
732
320
|
|
|
733
|
-
/**
|
|
734
|
-
Returns the first item with a property matching the passed value. You
|
|
735
|
-
can pass an optional second argument with the target value. Otherwise
|
|
736
|
-
this will match any property that evaluates to `true`.
|
|
737
|
-
This method works much like the more generic `find()` method.
|
|
738
|
-
Usage Example:
|
|
739
|
-
```javascript
|
|
740
|
-
let users = [
|
|
741
|
-
{ id: 1, name: 'Yehuda', isTom: false },
|
|
742
|
-
{ id: 2, name: 'Tom', isTom: true },
|
|
743
|
-
{ id: 3, name: 'Melanie', isTom: false },
|
|
744
|
-
{ id: 4, name: 'Leah', isTom: false }
|
|
745
|
-
];
|
|
746
|
-
users.findBy('id', 4); // { id: 4, name: 'Leah', isTom: false }
|
|
747
|
-
users.findBy('name', 'Melanie'); // { id: 3, name: 'Melanie', isTom: false }
|
|
748
|
-
users.findBy('isTom'); // { id: 2, name: 'Tom', isTom: true }
|
|
749
|
-
```
|
|
750
|
-
@method findBy
|
|
751
|
-
@param {String} key the property to test
|
|
752
|
-
@param {String} [value] optional value to test against.
|
|
753
|
-
@return {Object} found item or `undefined`
|
|
754
|
-
@public
|
|
755
|
-
*/
|
|
756
321
|
findBy() {
|
|
757
322
|
// @ts-expect-error TS doesn't like the ...arguments spread here.
|
|
758
323
|
let callback = iter(...arguments);
|
|
759
324
|
return find(this, callback);
|
|
760
325
|
},
|
|
761
326
|
|
|
762
|
-
/**
|
|
763
|
-
Returns `true` if the passed function returns true for every item in the
|
|
764
|
-
enumeration. This corresponds with the `Array.prototype.every()` method defined in ES5.
|
|
765
|
-
The callback method should have the following signature:
|
|
766
|
-
```javascript
|
|
767
|
-
function(item, index, array);
|
|
768
|
-
```
|
|
769
|
-
- `item` is the current item in the iteration.
|
|
770
|
-
- `index` is the current index in the iteration.
|
|
771
|
-
- `array` is the array itself.
|
|
772
|
-
All params are optional. The method should return `true` or `false`.
|
|
773
|
-
Note that in addition to a callback, you can also pass an optional target
|
|
774
|
-
object that will be set as `this` on the context. This is a good way
|
|
775
|
-
to give your iterator function access to the current object.
|
|
776
|
-
Usage example:
|
|
777
|
-
```javascript
|
|
778
|
-
function isAdult(person) {
|
|
779
|
-
return person.age > 18;
|
|
780
|
-
};
|
|
781
|
-
const people = Ember.A([{ name: 'John', age: 24 }, { name: 'Joan', age: 45 }]);
|
|
782
|
-
const areAllAdults = people.every(isAdult);
|
|
783
|
-
```
|
|
784
|
-
@method every
|
|
785
|
-
@param {Function} callback The callback to execute
|
|
786
|
-
@param {Object} [target] The target object to use
|
|
787
|
-
@return {Boolean}
|
|
788
|
-
@public
|
|
789
|
-
*/
|
|
790
327
|
every(callback, target = null) {
|
|
791
328
|
assert('`every` expects a function as first argument.', typeof callback === 'function');
|
|
792
329
|
return every(this, callback, target);
|
|
793
330
|
},
|
|
794
331
|
|
|
795
|
-
/**
|
|
796
|
-
Returns `true` if the passed property resolves to the value of the second
|
|
797
|
-
argument for all items in the array. This method is often simpler/faster
|
|
798
|
-
than using a callback.
|
|
799
|
-
Note that like the native `Array.every`, `isEvery` will return true when called
|
|
800
|
-
on any empty array.
|
|
801
|
-
```javascript
|
|
802
|
-
class Language {
|
|
803
|
-
constructor(name, isProgrammingLanguage) {
|
|
804
|
-
this.name = name;
|
|
805
|
-
this.programmingLanguage = isProgrammingLanguage;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
const compiledLanguages = [
|
|
809
|
-
new Language('Java', true),
|
|
810
|
-
new Language('Go', true),
|
|
811
|
-
new Language('Rust', true)
|
|
812
|
-
]
|
|
813
|
-
const languagesKnownByMe = [
|
|
814
|
-
new Language('Javascript', true),
|
|
815
|
-
new Language('English', false),
|
|
816
|
-
new Language('Ruby', true)
|
|
817
|
-
]
|
|
818
|
-
compiledLanguages.isEvery('programmingLanguage'); // true
|
|
819
|
-
languagesKnownByMe.isEvery('programmingLanguage'); // false
|
|
820
|
-
```
|
|
821
|
-
@method isEvery
|
|
822
|
-
@param {String} key the property to test
|
|
823
|
-
@param {String} [value] optional value to test against. Defaults to `true`
|
|
824
|
-
@return {Boolean}
|
|
825
|
-
@since 1.3.0
|
|
826
|
-
@public
|
|
827
|
-
*/
|
|
828
332
|
isEvery() {
|
|
829
333
|
// @ts-expect-error TS doesn't like the ...arguments spread here.
|
|
830
334
|
let callback = iter(...arguments);
|
|
831
335
|
return every(this, callback);
|
|
832
336
|
},
|
|
833
337
|
|
|
834
|
-
/**
|
|
835
|
-
The any() method executes the callback function once for each element
|
|
836
|
-
present in the array until it finds the one where callback returns a truthy
|
|
837
|
-
value (i.e. `true`). If such an element is found, any() immediately returns
|
|
838
|
-
true. Otherwise, any() returns false.
|
|
839
|
-
```javascript
|
|
840
|
-
function(item, index, array);
|
|
841
|
-
```
|
|
842
|
-
- `item` is the current item in the iteration.
|
|
843
|
-
- `index` is the current index in the iteration.
|
|
844
|
-
- `array` is the array object itself.
|
|
845
|
-
Note that in addition to a callback, you can also pass an optional target
|
|
846
|
-
object that will be set as `this` on the context. It can be a good way
|
|
847
|
-
to give your iterator function access to an object in cases where an ES6
|
|
848
|
-
arrow function would not be appropriate.
|
|
849
|
-
Usage Example:
|
|
850
|
-
```javascript
|
|
851
|
-
let includesManager = people.any(this.findPersonInManagersList, this);
|
|
852
|
-
let includesStockHolder = people.any(person => {
|
|
853
|
-
return this.findPersonInStockHoldersList(person)
|
|
854
|
-
});
|
|
855
|
-
if (includesManager || includesStockHolder) {
|
|
856
|
-
Paychecks.addBiggerBonus();
|
|
857
|
-
}
|
|
858
|
-
```
|
|
859
|
-
@method any
|
|
860
|
-
@param {Function} callback The callback to execute
|
|
861
|
-
@param {Object} [target] The target object to use
|
|
862
|
-
@return {Boolean} `true` if the passed function returns `true` for any item
|
|
863
|
-
@public
|
|
864
|
-
*/
|
|
865
338
|
any(callback, target = null) {
|
|
866
339
|
assert('`any` expects a function as first argument.', typeof callback === 'function');
|
|
867
340
|
return any(this, callback, target);
|
|
868
341
|
},
|
|
869
342
|
|
|
870
|
-
/**
|
|
871
|
-
Returns `true` if the passed property resolves to the value of the second
|
|
872
|
-
argument for any item in the array. This method is often simpler/faster
|
|
873
|
-
than using a callback.
|
|
874
|
-
Example usage:
|
|
875
|
-
```javascript
|
|
876
|
-
const food = [
|
|
877
|
-
{ food: 'apple', isFruit: true },
|
|
878
|
-
{ food: 'bread', isFruit: false },
|
|
879
|
-
{ food: 'banana', isFruit: true }
|
|
880
|
-
];
|
|
881
|
-
food.isAny('isFruit'); // true
|
|
882
|
-
```
|
|
883
|
-
@method isAny
|
|
884
|
-
@param {String} key the property to test
|
|
885
|
-
@param {String} [value] optional value to test against. Defaults to `true`
|
|
886
|
-
@return {Boolean}
|
|
887
|
-
@since 1.3.0
|
|
888
|
-
@public
|
|
889
|
-
*/
|
|
890
343
|
isAny() {
|
|
891
344
|
// @ts-expect-error TS doesn't like us using arguments like this
|
|
892
345
|
let callback = iter(...arguments);
|
|
893
346
|
return any(this, callback);
|
|
894
347
|
},
|
|
895
348
|
|
|
896
|
-
/**
|
|
897
|
-
This will combine the values of the array into a single value. It
|
|
898
|
-
is a useful way to collect a summary value from an array. This
|
|
899
|
-
corresponds to the `reduce()` method defined in JavaScript 1.8.
|
|
900
|
-
The callback method you provide should have the following signature (all
|
|
901
|
-
parameters are optional):
|
|
902
|
-
```javascript
|
|
903
|
-
function(previousValue, item, index, array);
|
|
904
|
-
```
|
|
905
|
-
- `previousValue` is the value returned by the last call to the iterator.
|
|
906
|
-
- `item` is the current item in the iteration.
|
|
907
|
-
- `index` is the current index in the iteration.
|
|
908
|
-
- `array` is the array itself.
|
|
909
|
-
Return the new cumulative value.
|
|
910
|
-
In addition to the callback you can also pass an `initialValue`. An error
|
|
911
|
-
will be raised if you do not pass an initial value and the enumerator is
|
|
912
|
-
empty.
|
|
913
|
-
Note that unlike the other methods, this method does not allow you to
|
|
914
|
-
pass a target object to set as this for the callback. It's part of the
|
|
915
|
-
spec. Sorry.
|
|
916
|
-
Example Usage:
|
|
917
|
-
```javascript
|
|
918
|
-
let numbers = [1, 2, 3, 4, 5];
|
|
919
|
-
numbers.reduce(function(summation, current) {
|
|
920
|
-
return summation + current;
|
|
921
|
-
}); // 15 (1 + 2 + 3 + 4 + 5)
|
|
922
|
-
numbers.reduce(function(summation, current) {
|
|
923
|
-
return summation + current;
|
|
924
|
-
}, -15); // 0 (-15 + 1 + 2 + 3 + 4 + 5)
|
|
925
|
-
|
|
926
|
-
let binaryValues = [true, false, false];
|
|
927
|
-
binaryValues.reduce(function(truthValue, current) {
|
|
928
|
-
return truthValue && current;
|
|
929
|
-
}); // false (true && false && false)
|
|
930
|
-
```
|
|
931
|
-
@method reduce
|
|
932
|
-
@param {Function} callback The callback to execute
|
|
933
|
-
@param {Object} initialValue Initial value for the reduce
|
|
934
|
-
@return {Object} The reduced value.
|
|
935
|
-
@public
|
|
936
|
-
*/
|
|
937
349
|
// FIXME: When called without initialValue, behavior does not match native behavior
|
|
938
350
|
reduce(callback, initialValue) {
|
|
939
351
|
assert('`reduce` expects a function as first argument.', typeof callback === 'function');
|
|
@@ -944,30 +356,6 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
944
356
|
return ret;
|
|
945
357
|
},
|
|
946
358
|
|
|
947
|
-
/**
|
|
948
|
-
Invokes the named method on every object in the receiver that
|
|
949
|
-
implements it. This method corresponds to the implementation in
|
|
950
|
-
Prototype 1.6.
|
|
951
|
-
```javascript
|
|
952
|
-
class Person {
|
|
953
|
-
name = null;
|
|
954
|
-
constructor(name) {
|
|
955
|
-
this.name = name;
|
|
956
|
-
}
|
|
957
|
-
greet(prefix='Hello') {
|
|
958
|
-
return `${prefix} ${this.name}`;
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
let people = [new Person('Joe'), new Person('Matt')];
|
|
962
|
-
people.invoke('greet'); // ['Hello Joe', 'Hello Matt']
|
|
963
|
-
people.invoke('greet', 'Bonjour'); // ['Bonjour Joe', 'Bonjour Matt']
|
|
964
|
-
```
|
|
965
|
-
@method invoke
|
|
966
|
-
@param {String} methodName the name of the method
|
|
967
|
-
@param {Object...} args optional arguments to pass as well.
|
|
968
|
-
@return {Array} return values from calling invoke.
|
|
969
|
-
@public
|
|
970
|
-
*/
|
|
971
359
|
invoke(methodName, ...args) {
|
|
972
360
|
let ret = A(); // SAFETY: This is not entirely safe and the code will not work with Ember proxies
|
|
973
361
|
|
|
@@ -979,80 +367,18 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
979
367
|
return ret;
|
|
980
368
|
},
|
|
981
369
|
|
|
982
|
-
/**
|
|
983
|
-
Simply converts the object into a genuine array. The order is not
|
|
984
|
-
guaranteed. Corresponds to the method implemented by Prototype.
|
|
985
|
-
@method toArray
|
|
986
|
-
@return {Array} the object as an array.
|
|
987
|
-
@public
|
|
988
|
-
*/
|
|
989
370
|
toArray() {
|
|
990
371
|
return this.map(item => item);
|
|
991
372
|
},
|
|
992
373
|
|
|
993
|
-
/**
|
|
994
|
-
Returns a copy of the array with all `null` and `undefined` elements removed.
|
|
995
|
-
```javascript
|
|
996
|
-
let arr = ['a', null, 'c', undefined];
|
|
997
|
-
arr.compact(); // ['a', 'c']
|
|
998
|
-
```
|
|
999
|
-
@method compact
|
|
1000
|
-
@return {Array} the array without null and undefined elements.
|
|
1001
|
-
@public
|
|
1002
|
-
*/
|
|
1003
374
|
compact() {
|
|
1004
375
|
return this.filter(value => value != null);
|
|
1005
376
|
},
|
|
1006
377
|
|
|
1007
|
-
/**
|
|
1008
|
-
Used to determine if the array contains the passed object.
|
|
1009
|
-
Returns `true` if found, `false` otherwise.
|
|
1010
|
-
The optional `startAt` argument can be used to pass a starting
|
|
1011
|
-
index to search from, effectively slicing the searchable portion
|
|
1012
|
-
of the array. If it's negative it will add the array length to
|
|
1013
|
-
the startAt value passed in as the index to search from. If less
|
|
1014
|
-
than or equal to `-1 * array.length` the entire array is searched.
|
|
1015
|
-
This method has the same behavior of JavaScript's [Array.includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes).
|
|
1016
|
-
```javascript
|
|
1017
|
-
[1, 2, 3].includes(2); // true
|
|
1018
|
-
[1, 2, 3].includes(4); // false
|
|
1019
|
-
[1, 2, 3].includes(3, 2); // true
|
|
1020
|
-
[1, 2, 3].includes(3, 3); // false
|
|
1021
|
-
[1, 2, 3].includes(3, -1); // true
|
|
1022
|
-
[1, 2, 3].includes(1, -1); // false
|
|
1023
|
-
[1, 2, 3].includes(1, -4); // true
|
|
1024
|
-
[1, 2, NaN].includes(NaN); // true
|
|
1025
|
-
```
|
|
1026
|
-
@method includes
|
|
1027
|
-
@param {Object} object The object to search for.
|
|
1028
|
-
@param {Number} startAt optional starting location to search, default 0
|
|
1029
|
-
@return {Boolean} `true` if object is found in the array.
|
|
1030
|
-
@public
|
|
1031
|
-
*/
|
|
1032
378
|
includes(object, startAt) {
|
|
1033
379
|
return indexOf(this, object, startAt, true) !== -1;
|
|
1034
380
|
},
|
|
1035
381
|
|
|
1036
|
-
/**
|
|
1037
|
-
Sorts the array by the keys specified in the argument.
|
|
1038
|
-
You may provide multiple arguments to sort by multiple properties.
|
|
1039
|
-
```javascript
|
|
1040
|
-
let colors = [
|
|
1041
|
-
{ name: 'red', weight: 500 },
|
|
1042
|
-
{ name: 'green', weight: 600 },
|
|
1043
|
-
{ name: 'blue', weight: 500 }
|
|
1044
|
-
];
|
|
1045
|
-
colors.sortBy('name');
|
|
1046
|
-
// [{name: 'blue', weight: 500}, {name: 'green', weight: 600}, {name: 'red', weight: 500}]
|
|
1047
|
-
colors.sortBy('weight', 'name');
|
|
1048
|
-
// [{name: 'blue', weight: 500}, {name: 'red', weight: 500}, {name: 'green', weight: 600}]
|
|
1049
|
-
```
|
|
1050
|
-
@method sortBy
|
|
1051
|
-
@param {String} property name(s) to sort on
|
|
1052
|
-
@return {Array} The sorted array.
|
|
1053
|
-
@since 1.2.0
|
|
1054
|
-
@public
|
|
1055
|
-
*/
|
|
1056
382
|
sortBy() {
|
|
1057
383
|
let sortKeys = arguments;
|
|
1058
384
|
return this.toArray().sort((a, b) => {
|
|
@@ -1072,53 +398,14 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
1072
398
|
});
|
|
1073
399
|
},
|
|
1074
400
|
|
|
1075
|
-
/**
|
|
1076
|
-
Returns a new array that contains only unique values. The default
|
|
1077
|
-
implementation returns an array regardless of the receiver type.
|
|
1078
|
-
```javascript
|
|
1079
|
-
let arr = ['a', 'a', 'b', 'b'];
|
|
1080
|
-
arr.uniq(); // ['a', 'b']
|
|
1081
|
-
```
|
|
1082
|
-
This only works on primitive data types, e.g. Strings, Numbers, etc.
|
|
1083
|
-
@method uniq
|
|
1084
|
-
@return {EmberArray}
|
|
1085
|
-
@public
|
|
1086
|
-
*/
|
|
1087
401
|
uniq() {
|
|
1088
402
|
return uniqBy(this);
|
|
1089
403
|
},
|
|
1090
404
|
|
|
1091
|
-
/**
|
|
1092
|
-
Returns a new array that contains only items containing a unique property value.
|
|
1093
|
-
The default implementation returns an array regardless of the receiver type.
|
|
1094
|
-
```javascript
|
|
1095
|
-
let arr = [{ value: 'a' }, { value: 'a' }, { value: 'b' }, { value: 'b' }];
|
|
1096
|
-
arr.uniqBy('value'); // [{ value: 'a' }, { value: 'b' }]
|
|
1097
|
-
let arr = [2.2, 2.1, 3.2, 3.3];
|
|
1098
|
-
arr.uniqBy(Math.floor); // [2.2, 3.2];
|
|
1099
|
-
```
|
|
1100
|
-
@method uniqBy
|
|
1101
|
-
@param {String,Function} key
|
|
1102
|
-
@return {EmberArray}
|
|
1103
|
-
@public
|
|
1104
|
-
*/
|
|
1105
405
|
uniqBy(key) {
|
|
1106
406
|
return uniqBy(this, key);
|
|
1107
407
|
},
|
|
1108
408
|
|
|
1109
|
-
/**
|
|
1110
|
-
Returns a new array that excludes the passed value. The default
|
|
1111
|
-
implementation returns an array regardless of the receiver type.
|
|
1112
|
-
If the receiver does not contain the value it returns the original array.
|
|
1113
|
-
```javascript
|
|
1114
|
-
let arr = ['a', 'b', 'a', 'c'];
|
|
1115
|
-
arr.without('a'); // ['b', 'c']
|
|
1116
|
-
```
|
|
1117
|
-
@method without
|
|
1118
|
-
@param {Object} value
|
|
1119
|
-
@return {EmberArray}
|
|
1120
|
-
@public
|
|
1121
|
-
*/
|
|
1122
409
|
without(value) {
|
|
1123
410
|
if (!this.includes(value)) {
|
|
1124
411
|
return this; // nothing to do
|
|
@@ -1131,35 +418,6 @@ const EmberArray = Mixin.create(Enumerable, {
|
|
|
1131
418
|
|
|
1132
419
|
});
|
|
1133
420
|
const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
|
|
1134
|
-
/**
|
|
1135
|
-
__Required.__ You must implement this method to apply this mixin.
|
|
1136
|
-
This is one of the primitives you must implement to support `Array`.
|
|
1137
|
-
You should replace amt objects started at idx with the objects in the
|
|
1138
|
-
passed array.
|
|
1139
|
-
Note that this method is expected to validate the type(s) of objects that it expects.
|
|
1140
|
-
@method replace
|
|
1141
|
-
@param {Number} idx Starting index in the array to replace. If
|
|
1142
|
-
idx >= length, then append to the end of the array.
|
|
1143
|
-
@param {Number} amt Number of elements that should be removed from
|
|
1144
|
-
the array, starting at *idx*.
|
|
1145
|
-
@param {EmberArray} [objects] An optional array of zero or more objects that should be
|
|
1146
|
-
inserted into the array at *idx*
|
|
1147
|
-
@public
|
|
1148
|
-
*/
|
|
1149
|
-
|
|
1150
|
-
/**
|
|
1151
|
-
Remove all elements from the array. This is useful if you
|
|
1152
|
-
want to reuse an existing array without having to recreate it.
|
|
1153
|
-
```javascript
|
|
1154
|
-
let colors = ['red', 'green', 'blue'];
|
|
1155
|
-
colors.length; // 3
|
|
1156
|
-
colors.clear(); // []
|
|
1157
|
-
colors.length; // 0
|
|
1158
|
-
```
|
|
1159
|
-
@method clear
|
|
1160
|
-
@return {Array} An empty Array.
|
|
1161
|
-
@public
|
|
1162
|
-
*/
|
|
1163
421
|
clear() {
|
|
1164
422
|
let len = this.length;
|
|
1165
423
|
|
|
@@ -1171,92 +429,24 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
|
|
|
1171
429
|
return this;
|
|
1172
430
|
},
|
|
1173
431
|
|
|
1174
|
-
/**
|
|
1175
|
-
This will use the primitive `replace()` method to insert an object at the
|
|
1176
|
-
specified index.
|
|
1177
|
-
```javascript
|
|
1178
|
-
let colors = ['red', 'green', 'blue'];
|
|
1179
|
-
colors.insertAt(2, 'yellow'); // ['red', 'green', 'yellow', 'blue']
|
|
1180
|
-
colors.insertAt(5, 'orange'); // Error: Index out of range
|
|
1181
|
-
```
|
|
1182
|
-
@method insertAt
|
|
1183
|
-
@param {Number} idx index of insert the object at.
|
|
1184
|
-
@param {Object} object object to insert
|
|
1185
|
-
@return {EmberArray} receiver
|
|
1186
|
-
@public
|
|
1187
|
-
*/
|
|
1188
432
|
insertAt(idx, object) {
|
|
1189
433
|
insertAt(this, idx, object);
|
|
1190
434
|
return this;
|
|
1191
435
|
},
|
|
1192
436
|
|
|
1193
|
-
/**
|
|
1194
|
-
Remove an object at the specified index using the `replace()` primitive
|
|
1195
|
-
method. You can pass either a single index, or a start and a length.
|
|
1196
|
-
If you pass a start and length that is beyond the
|
|
1197
|
-
length this method will throw an assertion.
|
|
1198
|
-
```javascript
|
|
1199
|
-
let colors = ['red', 'green', 'blue', 'yellow', 'orange'];
|
|
1200
|
-
colors.removeAt(0); // ['green', 'blue', 'yellow', 'orange']
|
|
1201
|
-
colors.removeAt(2, 2); // ['green', 'blue']
|
|
1202
|
-
colors.removeAt(4, 2); // Error: Index out of range
|
|
1203
|
-
```
|
|
1204
|
-
@method removeAt
|
|
1205
|
-
@param {Number} start index, start of range
|
|
1206
|
-
@param {Number} len length of passing range
|
|
1207
|
-
@return {EmberArray} receiver
|
|
1208
|
-
@public
|
|
1209
|
-
*/
|
|
1210
437
|
removeAt(start, len) {
|
|
1211
438
|
return removeAt(this, start, len);
|
|
1212
439
|
},
|
|
1213
440
|
|
|
1214
|
-
/**
|
|
1215
|
-
Push the object onto the end of the array. Works just like `push()` but it
|
|
1216
|
-
is KVO-compliant.
|
|
1217
|
-
```javascript
|
|
1218
|
-
let colors = ['red', 'green'];
|
|
1219
|
-
colors.pushObject('black'); // ['red', 'green', 'black']
|
|
1220
|
-
colors.pushObject(['yellow']); // ['red', 'green', ['yellow']]
|
|
1221
|
-
```
|
|
1222
|
-
@method pushObject
|
|
1223
|
-
@param {*} obj object to push
|
|
1224
|
-
@return object same object passed as a param
|
|
1225
|
-
@public
|
|
1226
|
-
*/
|
|
1227
441
|
pushObject(obj) {
|
|
1228
442
|
return insertAt(this, this.length, obj);
|
|
1229
443
|
},
|
|
1230
444
|
|
|
1231
|
-
/**
|
|
1232
|
-
Add the objects in the passed array to the end of the array. Defers
|
|
1233
|
-
notifying observers of the change until all objects are added.
|
|
1234
|
-
```javascript
|
|
1235
|
-
let colors = ['red'];
|
|
1236
|
-
colors.pushObjects(['yellow', 'orange']); // ['red', 'yellow', 'orange']
|
|
1237
|
-
```
|
|
1238
|
-
@method pushObjects
|
|
1239
|
-
@param {Array} objects the objects to add
|
|
1240
|
-
@return {MutableArray} receiver
|
|
1241
|
-
@public
|
|
1242
|
-
*/
|
|
1243
445
|
pushObjects(objects) {
|
|
1244
446
|
this.replace(this.length, 0, objects);
|
|
1245
447
|
return this;
|
|
1246
448
|
},
|
|
1247
449
|
|
|
1248
|
-
/**
|
|
1249
|
-
Pop object from array or nil if none are left. Works just like `pop()` but
|
|
1250
|
-
it is KVO-compliant.
|
|
1251
|
-
```javascript
|
|
1252
|
-
let colors = ['red', 'green', 'blue'];
|
|
1253
|
-
colors.popObject(); // 'blue'
|
|
1254
|
-
console.log(colors); // ['red', 'green']
|
|
1255
|
-
```
|
|
1256
|
-
@method popObject
|
|
1257
|
-
@return object
|
|
1258
|
-
@public
|
|
1259
|
-
*/
|
|
1260
450
|
popObject() {
|
|
1261
451
|
let len = this.length;
|
|
1262
452
|
|
|
@@ -1269,18 +459,6 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
|
|
|
1269
459
|
return ret;
|
|
1270
460
|
},
|
|
1271
461
|
|
|
1272
|
-
/**
|
|
1273
|
-
Shift an object from start of array or nil if none are left. Works just
|
|
1274
|
-
like `shift()` but it is KVO-compliant.
|
|
1275
|
-
```javascript
|
|
1276
|
-
let colors = ['red', 'green', 'blue'];
|
|
1277
|
-
colors.shiftObject(); // 'red'
|
|
1278
|
-
console.log(colors); // ['green', 'blue']
|
|
1279
|
-
```
|
|
1280
|
-
@method shiftObject
|
|
1281
|
-
@return object
|
|
1282
|
-
@public
|
|
1283
|
-
*/
|
|
1284
462
|
shiftObject() {
|
|
1285
463
|
if (this.length === 0) {
|
|
1286
464
|
return null;
|
|
@@ -1291,48 +469,15 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
|
|
|
1291
469
|
return ret;
|
|
1292
470
|
},
|
|
1293
471
|
|
|
1294
|
-
/**
|
|
1295
|
-
Unshift an object to start of array. Works just like `unshift()` but it is
|
|
1296
|
-
KVO-compliant.
|
|
1297
|
-
```javascript
|
|
1298
|
-
let colors = ['red'];
|
|
1299
|
-
colors.unshiftObject('yellow'); // ['yellow', 'red']
|
|
1300
|
-
colors.unshiftObject(['black']); // [['black'], 'yellow', 'red']
|
|
1301
|
-
```
|
|
1302
|
-
@method unshiftObject
|
|
1303
|
-
@param {*} obj object to unshift
|
|
1304
|
-
@return object same object passed as a param
|
|
1305
|
-
@public
|
|
1306
|
-
*/
|
|
1307
472
|
unshiftObject(obj) {
|
|
1308
473
|
return insertAt(this, 0, obj);
|
|
1309
474
|
},
|
|
1310
475
|
|
|
1311
|
-
/**
|
|
1312
|
-
Adds the named objects to the beginning of the array. Defers notifying
|
|
1313
|
-
observers until all objects have been added.
|
|
1314
|
-
```javascript
|
|
1315
|
-
let colors = ['red'];
|
|
1316
|
-
colors.unshiftObjects(['black', 'white']); // ['black', 'white', 'red']
|
|
1317
|
-
colors.unshiftObjects('yellow'); // Type Error: 'undefined' is not a function
|
|
1318
|
-
```
|
|
1319
|
-
@method unshiftObjects
|
|
1320
|
-
@param {Enumerable} objects the objects to add
|
|
1321
|
-
@return {EmberArray} receiver
|
|
1322
|
-
@public
|
|
1323
|
-
*/
|
|
1324
476
|
unshiftObjects(objects) {
|
|
1325
477
|
this.replace(0, 0, objects);
|
|
1326
478
|
return this;
|
|
1327
479
|
},
|
|
1328
480
|
|
|
1329
|
-
/**
|
|
1330
|
-
Reverse objects in the array. Works just like `reverse()` but it is
|
|
1331
|
-
KVO-compliant.
|
|
1332
|
-
@method reverseObjects
|
|
1333
|
-
@return {EmberArray} receiver
|
|
1334
|
-
@public
|
|
1335
|
-
*/
|
|
1336
481
|
reverseObjects() {
|
|
1337
482
|
let len = this.length;
|
|
1338
483
|
|
|
@@ -1345,20 +490,6 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
|
|
|
1345
490
|
return this;
|
|
1346
491
|
},
|
|
1347
492
|
|
|
1348
|
-
/**
|
|
1349
|
-
Replace all the receiver's content with content of the argument.
|
|
1350
|
-
If argument is an empty array receiver will be cleared.
|
|
1351
|
-
```javascript
|
|
1352
|
-
let colors = ['red', 'green', 'blue'];
|
|
1353
|
-
colors.setObjects(['black', 'white']); // ['black', 'white']
|
|
1354
|
-
colors.setObjects([]); // []
|
|
1355
|
-
```
|
|
1356
|
-
@method setObjects
|
|
1357
|
-
@param {EmberArray} objects array whose content will be used for replacing
|
|
1358
|
-
the content of the receiver
|
|
1359
|
-
@return {EmberArray} receiver with the new content
|
|
1360
|
-
@public
|
|
1361
|
-
*/
|
|
1362
493
|
setObjects(objects) {
|
|
1363
494
|
if (objects.length === 0) {
|
|
1364
495
|
return this.clear();
|
|
@@ -1369,19 +500,6 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
|
|
|
1369
500
|
return this;
|
|
1370
501
|
},
|
|
1371
502
|
|
|
1372
|
-
/**
|
|
1373
|
-
Remove all occurrences of an object in the array.
|
|
1374
|
-
```javascript
|
|
1375
|
-
let cities = ['Chicago', 'Berlin', 'Lima', 'Chicago'];
|
|
1376
|
-
cities.removeObject('Chicago'); // ['Berlin', 'Lima']
|
|
1377
|
-
cities.removeObject('Lima'); // ['Berlin']
|
|
1378
|
-
cities.removeObject('Tokyo') // ['Berlin']
|
|
1379
|
-
```
|
|
1380
|
-
@method removeObject
|
|
1381
|
-
@param {*} obj object to remove
|
|
1382
|
-
@return {EmberArray} receiver
|
|
1383
|
-
@public
|
|
1384
|
-
*/
|
|
1385
503
|
removeObject(obj) {
|
|
1386
504
|
let loc = this.length || 0;
|
|
1387
505
|
|
|
@@ -1396,13 +514,6 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
|
|
|
1396
514
|
return this;
|
|
1397
515
|
},
|
|
1398
516
|
|
|
1399
|
-
/**
|
|
1400
|
-
Removes each object in the passed array from the receiver.
|
|
1401
|
-
@method removeObjects
|
|
1402
|
-
@param {EmberArray} objects the objects to remove
|
|
1403
|
-
@return {EmberArray} receiver
|
|
1404
|
-
@public
|
|
1405
|
-
*/
|
|
1406
517
|
removeObjects(objects) {
|
|
1407
518
|
beginPropertyChanges();
|
|
1408
519
|
|
|
@@ -1415,19 +526,6 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
|
|
|
1415
526
|
return this;
|
|
1416
527
|
},
|
|
1417
528
|
|
|
1418
|
-
/**
|
|
1419
|
-
Push the object onto the end of the array if it is not already
|
|
1420
|
-
present in the array.
|
|
1421
|
-
```javascript
|
|
1422
|
-
let cities = ['Chicago', 'Berlin'];
|
|
1423
|
-
cities.addObject('Lima'); // ['Chicago', 'Berlin', 'Lima']
|
|
1424
|
-
cities.addObject('Berlin'); // ['Chicago', 'Berlin', 'Lima']
|
|
1425
|
-
```
|
|
1426
|
-
@method addObject
|
|
1427
|
-
@param {*} obj object to add, if not already present
|
|
1428
|
-
@return {EmberArray} receiver
|
|
1429
|
-
@public
|
|
1430
|
-
*/
|
|
1431
529
|
addObject(obj) {
|
|
1432
530
|
let included = this.includes(obj);
|
|
1433
531
|
|
|
@@ -1438,13 +536,6 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
|
|
|
1438
536
|
return this;
|
|
1439
537
|
},
|
|
1440
538
|
|
|
1441
|
-
/**
|
|
1442
|
-
Adds each object in the passed array to the receiver.
|
|
1443
|
-
@method addObjects
|
|
1444
|
-
@param {EmberArray} objects the objects to add.
|
|
1445
|
-
@return {EmberArray} receiver
|
|
1446
|
-
@public
|
|
1447
|
-
*/
|
|
1448
539
|
addObjects(objects) {
|
|
1449
540
|
beginPropertyChanges();
|
|
1450
541
|
objects.forEach(obj => this.addObject(obj));
|