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';
Show:
filterByKeys
(
  • array
  • keys
)
Computed

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:

  • array String

    Key of the array (important this is the NAME of the array property, not the actual array itself)

  • keys Array

    Array of keys to check, must all be truthy

Returns:

Computed:

computed property

sortBy
(
  • array
  • keys
  • reverse
)
Computed

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:

  • array String

    Name of array to sort

  • keys String | Array

    Key or list of keys to sort by

  • reverse Boolean

    Optional param to sort the items in descending order. Default is false

Returns:

Computed:

Computed sort property

storePeekAll
(
  • model
)
Computed

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 String

    Model name to peek

Returns:

Computed:

Computed property