This Util is all about making common computed properties easier to use. It took several very common computed properties that are used throughout the apps and made them exportable, so each of them could be used with less code. Each returns a computed property for you, and will function the same as if you had written the simple computed property yourself. Watch properties will also automatically be done for you. Each of the "methods" in this documentation are actually different computed properties you are able to import.
Import syntax:
import {functionName} from '@bennerinformatics/ember-fw/utils/computed';
//where functionName is the name of the function, so for example, the "sortBy" function would have the following syntax
import {sortBy} from '@bennerinformatics/ember-fw/utils/computed';
Methods
-
array
-
keys
Filters an array by a list of keys, requiring every one to match. If you wish to filter by only one key, check out Ember's filterBy util.
Usage example:
filteredLocations: filterByKeys('sortedLocations', ['active', 'inDept']),
Parameters:
Returns:
computed property
-
array
-
keys
-
reverse
Computed macro that redirects to array sortBy. It can take one key or multiple, and it essentially sorts the array for you with anything that is able to be used by the sortBy method. Unfortunately since the vanilla sortBy function does not take 'key:asc' or 'key:desc', there needed to be a workaround for sorting in desc order. Unfortunately, this workaround does not allow you to sort one key desc and one key asc, but it will allow you to reverse the order of the array.
Usage Example:
//sort ascending model.locations by two keys, first order, then title
sortedLocations: sortBy('model.locations', ['order', 'title']),
//sort ascending model.users by one key, name
sortedUsers: sortBy('model.users', 'nameFull')
//sort descending model.entries by one key, date._d
sortedEntries: sortBy('model.entries', 'date._d', true),
Parameters:
Returns:
Computed sort property
-
model
Computed property that returns a call to store.peekAll. Will update accordingly. Note that this is a peekAll request not a findAll request, if you do not know the difference, see Ember Guides on the differences between the two.
Usage Example:
users: storePeekAll('user'),
Parameters:
-
model
StringModel name to peek
Returns:
Computed property