ember-macaroni
Keep your app code DRY and copypasta free with computed property macaronis (macros) for Ember.js 1.13.x and greater.
Why
Computed property macros (CPM) are great for DRYing up your code, and Ember.js ships with a few handy computed macros. This addon adds a few more functional-style macros, and can be thought of as the "lodash equivalent" of Ember CPM libraries.
Chaining is not supported... yet.
Usage
First, import the macro(s) you need, or the whole thing:
; // imports a named macro; // imports all the thingsconst findFromCollectionByValue = macros; // destructuring Component;
Available macros
Collection
findFromCollectionByKey
Returns the first item with a property matching the passed value from a dependent key.
@param {String} collectionKey
The key name for the collection@param {String} propName
The key name for the property to find by@param {String} valueKey
The key name that returns the value to find
EmberObject;
findFromCollectionByValue
Returns the first item with a property matching the passed value.
@param {String} collectionKey
The key name for the collection@param {String} propName
The key name for the property to find by@param {*} value
The value to match`
EmberObject;
rejectFromCollectionByKey
Returns an array with the items that do not match the passed value from a dependent key.
@param {String} collectionKey
The key name for the collection@param {String} propName
The key name for the property to reject by@param {String} valueKey
The key name that returns the value to reject
EmberObject;
rejectFromCollectionByValue
Returns an array with the items that do not match the passed value.
@param {String} collectionKey
The key name for the collection@param {String} propName
The key name for the property to reject by@param {*} value
The value to reject
EmberObject;
filterFromCollectionByKey
Returns an array with just the items with the matched property.
@param {String} collectionKey
The key name for the collection@param {String} propName
The key name for the property to filter by@param {String} valueKey
The key name that returns the value to filter
EmberObject;
filterFromCollectionByContains
Returns an array with just the items that are contained in another array.
@param {String} collectionKey
The key name for the collection@param {String} propName
The key name for the property to filter by@param {Array} values
The array of values to filter
EmberObject;
collectionWithoutKey
Returns an array without an item by dependent key.
@param {String} collectionKey
The key name for the collection@param {String} propName
The key name for the property to exclude
EmberObject;
reduceCollectionByKey
Combines the values of the enumerator into a single value, using a dependent key.
@param {String} collectionKey
The key name for the collection@param {String} dependentKey
The key name for the property to reduce@param {*} startValue
The initial value
EmberObject;
Truth
isEqualByKeys
Strict equality using dependent keys.
@param {String} firstKey
The key name for the first property@param {String} secondKey
The key name for the second property
EmberObject;
ifThenElseWithKeys
Ternary conditional with dependent keys.
@param {String} conditionalKey
The key name for the conditional property@param {String} trueKey
The key name for the property to return when the conditional is true@param {String} falseKey
The key name for the property to return when the conditional is false
EmberObject;
ifThenElseWithValues
Ternary conditional.
@param {String} conditionalKey
The key name for the conditional property@param {String} trueValue
The value to return when the conditional is true@param {String} falseValue
The value to return when the conditional is false
EmberObject;
gte
Greater than or equal to comparison between two dependent keys.
@param {String} lhsKey
The key name for the left hand side of the operator@param {String} rhsKey
The key name for the right hand side of the operator
EmberObject;
gt
Greater than comparison between two dependent keys.
@param {String} lhsKey
The key name for the left hand side of the operator@param {String} rhsKey
The key name for the right hand side of the operator
EmberObject;
lte
Lesser than or equal to comparison between two dependent keys.
@param {String} lhsKey
The key name for the left hand side of the operator@param {String} rhsKey
The key name for the right hand side of the operator
EmberObject;
lt
Lesser than comparison between two dependent keys.
@param {String} lhsKey
The key name for the left hand side of the operator@param {String} rhsKey
The key name for the right hand side of the operator
EmberObject;
General
getPropertiesByKeys
Returns a POJO containing all the key-values that match the dependent keys.
@param {...rest} dependentKeys
Argument list of dependent keys
EmberObject;
joinWith
Returns a string of values joined together with a separator.
@param {String} seperator
Separator to join values with@param {...rest} dependentKeys
Argument list of dependent keys
EmberObject;
Installation
git clone
this repositorynpm install
bower install
Running
ember server
- Visit your app at http://localhost:4200.
Running Tests
ember test
ember test --server
Building
ember build
For more information on using ember-cli, visit http://www.ember-cli.com/.