ember-array-computed-macros
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -13,2 +13,3 @@ import Ember from 'ember'; | ||
export var sort = Ember.computed.sort; | ||
export var sum = Ember.computed.sum; | ||
@@ -15,0 +16,0 @@ export var maxBy = function(listProperty, valueProperty) { |
{ | ||
"name": "ember-array-computed-macros", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "The default blueprint for ember-cli addons.", | ||
@@ -5,0 +5,0 @@ "directories": { |
# ember-array-computed-macros | ||
[![npm version](https://badge.fury.io/js/ember-array-computed-macros.svg)](http://badge.fury.io/js/ember-array-computed-macros) [![Build Status](https://travis-ci.org/martndemus/ember-array-computed-macros.svg?branch=master)](https://travis-ci.org/martndemus/ember-array-computed-macros) | ||
## Usage | ||
## Macros | ||
### Map | ||
This addon is supplemental to the already existing array computed macros existing in Ember.js | ||
#### `maxBy(listProperty, valueProperty)` | ||
Takes all values of `valueProperty` from `listProperty` and then picks the maximum value from that. | ||
Example: | ||
```js | ||
import Ember from 'ember'; | ||
import { map } from 'ember-array-computed-macros'; | ||
var ContactList = Ember.Component.extend({ | ||
highestAge: maxBy('people', 'age') | ||
}); | ||
export default Ember.Component.extend({ | ||
names: ['Tom', 'Yehuda'], | ||
upperCasedNames: map('names', (name) => name.toUpperCase()) | ||
}); | ||
const myContactList = ContactList.create({ | ||
people: [ | ||
{ first: 'Tom', last: 'Dale', age: 21 }, | ||
{ first: 'Yehuda', last: 'Katz', age: 42 } | ||
] | ||
}). | ||
myContactList.get('highestAge') // returns 42 | ||
``` | ||
### Map By | ||
### `minBy(listPropery, valueProperty)` | ||
See `maxBy`, except it takes the minimum value instead of the maximum. | ||
### `orderBy(listProperty, ...sortProperties)` | ||
Takes a `listProperty` and returns that list sorted by the `sortProperties`. | ||
Append `:desc` to the sort property to sort in reverse order for that property. | ||
```js | ||
@@ -26,41 +43,56 @@ import Ember from 'ember'; | ||
names: [ | ||
{ first: 'Tom', last: 'Dale' }, | ||
{ first: 'Yehuda', last: 'Katz' } | ||
{ first: 'Tom', last: 'Dale', age: 21 }, | ||
{ first: 'Yehuda', last: 'Katz', age: 42 } | ||
], | ||
firstNames: mapBy('names', 'first') | ||
oderedNames: orderBy('names', 'last', 'first'. 'age:desc') | ||
}); | ||
``` | ||
### Order By | ||
### `sumBy(listProperty, valueProperty)` | ||
Takes all values of `valueProperty` from `listProperty` and then sums those values. | ||
Example: | ||
```js | ||
import Ember from 'ember'; | ||
import { map } from 'ember-array-computed-macros'; | ||
var ContactList = Ember.Component.extend({ | ||
collectiveAge: sumBy('people', 'age') | ||
}); | ||
export default Ember.Component.extend({ | ||
names: [ | ||
const myContactList = ContactList.create({ | ||
people: [ | ||
{ first: 'Tom', last: 'Dale', age: 21 }, | ||
{ first: 'Yehuda', last: 'Katz', age: 42 } | ||
], | ||
oderedNames: orderBy('names', 'last', 'first'. 'age:desc') | ||
}); | ||
] | ||
}). | ||
myContactList.get('collectiveAge') // returns 53 | ||
``` | ||
### Other | ||
### `reverse(listProperty)` | ||
Reverses the array at `listProperty` with `Array.prototype.reverse`. | ||
### `everyBy(listPropery, valueProperty)` | ||
Takes all values of `valueProperty` from `listProperty` and then checks if all of those values are truthy. | ||
### `anyBy(listProperty, valueProperty)` | ||
Takes all values of `valueProperty` from `listProperty` and then checks if any of those values are truthy. | ||
### From Ember.js | ||
The addon re-exports all array computed macros from Ember.js for convenience. | ||
* map | ||
* mapBy | ||
* filter | ||
* filterBy | ||
* everyBy | ||
* anyBy | ||
* min | ||
* minBy | ||
* max | ||
* maxBy | ||
* reverse | ||
* sum | ||
* sort | ||
## Use with decorators | ||
## Decorators | ||
```js | ||
@@ -67,0 +99,0 @@ import Ember from 'ember'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10554
149
133