https://github.com/jclem/mutating-array
A mutating array for Ember
https://github.com/jclem/mutating-array
Last synced: 8 months ago
JSON representation
A mutating array for Ember
- Host: GitHub
- URL: https://github.com/jclem/mutating-array
- Owner: jclem
- License: mit
- Created: 2014-10-14T17:39:25.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-10-14T18:17:54.000Z (over 11 years ago)
- Last Synced: 2025-03-24T10:52:52.422Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 156 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Ember.MutatingArray [](https://travis-ci.org/jclem/mutating-array)
`Ember.MutatingArray` is an array mixin for Ember apps. It overrides the
[`replace`][replace] method of an [Ember.MutableArray][mutable-array] so that
a series of filters, and then a series of maps, are performed on the array
before any objects are added to it.
## Install
`bower install --save mutating-array`
## Usage
```javascript
// Create an array
var arr = [
{ firstName: 'Jonathan', lastName: 'Clem' },
{ firstName: 'George', lastName: 'Jones' }
];
// Turn it into a MutatingArray
arr = Ember.MutatingArray.apply(arr);
// Add some filters
arr.get('filters').pushObject(function onlyJoneses(item) {
return item.lastName === 'Jones';
});
// Add some maps
arr.get('maps').pushObject(function nickNames(item) {
if (item.firstName === 'George') {
item.nickname = 'The Possum';
}
return item;
});
arr.toArray(); // [{ firstName: 'George', lastName: 'Jones', nickname: 'The Possum' }];
arr.pushObject({ firstName: 'George', lastName: 'Bush' });
arr.toArray(); // [{ firstName: 'George', lastName: 'Jones', nickname: 'The Possum' }];
arr.pushObject({ firstName: 'Chuck', lastName: 'Jones' });
arr.toArray(); // [
// { firstName: 'George', lastName: 'Jones', nickname: 'The Possum' },
// { firstName: 'Chuck', lastName: 'Jones' }
// ];
```
[replace]: http://emberjs.com/api/classes/Ember.MutableArray.html#method_replace
[mutable-array]: http://emberjs.com/api/classes/Ember.MutableArray.html