Class @ember/object/computed
| Module: | @ember/object |
|---|
alias (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:518
import { alias } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which creates an alias to the original value for property.
Creates a new property that is an alias for another property on an object. Calls to get or set this property behave as though they were called on the original property.
let Person = Ember.Object.extend({
name: 'Alex Matchneer',
nomen: Ember.computed.alias('name')
});
let alex = Person.create();
alex.get('nomen'); // 'Alex Matchneer'
alex.get('name'); // 'Alex Matchneer'
alex.set('nomen', '@machty');
alex.get('name'); // '@machty' and (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:440
import { and } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which performs a logical `and` on the values of all the original values for properties.
A computed property that performs a logical and on the original values for the provided dependent properties.
You may pass in more than two properties and even use property brace expansion. The computed property will return the first falsy value or last truthy value just like JavaScript's && operator.
Example
let Hamster = Ember.Object.extend({
readyForCamp: Ember.computed.and('hasTent', 'hasBackpack'),
readyForHike: Ember.computed.and('hasWalkingStick', 'hasBackpack')
});
let tomster = Hamster.create();
tomster.get('readyForCamp'); // false
tomster.set('hasTent', true);
tomster.get('readyForCamp'); // false
tomster.set('hasBackpack', true);
tomster.get('readyForCamp'); // true
tomster.set('hasBackpack', 'Yes');
tomster.get('readyForCamp'); // 'Yes'
tomster.set('hasWalkingStick', null);
tomster.get('readyForHike'); // null bool (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:194
import { bool } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which converts to boolean the original value for property
A computed property that converts the provided dependent property into a boolean value.
let Hamster = Ember.Object.extend({
hasBananas: Ember.computed.bool('numBananas')
});
let hamster = Hamster.create();
hamster.get('hasBananas'); // false
hamster.set('numBananas', 0);
hamster.get('hasBananas'); // false
hamster.set('numBananas', 1);
hamster.get('hasBananas'); // true
hamster.set('numBananas', null);
hamster.get('hasBananas'); // false collect (dependentKey) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:633
import { collect } from '@ember/object/computed'; - dependentKey
- String
- returns
- Ember.ComputedProperty
- computed property which maps values of all passed in properties to an array.
A computed property that returns the array of values for the provided dependent properties.
Example
let Hamster = Ember.Object.extend({
clothes: Ember.computed.collect('hat', 'shirt')
});
let hamster = Hamster.create();
hamster.get('clothes'); // [null, null]
hamster.set('hat', 'Camp Hat');
hamster.set('shirt', 'Camp Shirt');
hamster.get('clothes'); // ['Camp Hat', 'Camp Shirt'] deprecatingAlias (dependentKey, options) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:638
Available since v1.7.0
import { deprecatingAlias } from '@ember/object/computed'; - dependentKey
- String
- options
- Object
- Options for `Ember.deprecate`.
- returns
- ComputedProperty
- computed property which creates an alias with a deprecation to the original value for property.
Creates a new property that is an alias for another property on an object. Calls to get or set this property behave as though they were called on the original property, but also print a deprecation warning.
let Hamster = Ember.Object.extend({
bananaCount: Ember.computed.deprecatingAlias('cavendishCount', {
id: 'hamster.deprecate-banana',
until: '3.0.0'
})
});
let hamster = Hamster.create();
hamster.set('bananaCount', 5); // Prints a deprecation warning.
hamster.get('cavendishCount'); // 5 empty (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:58
Available since v1.6.0
import { empty } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which returns true if the value of the dependent property is null, an empty string, empty array, or empty function and false if the underlying value is not empty.
A computed property that returns true if the value of the dependent property is null, an empty string, empty array, or empty function.
Example
let ToDoList = Ember.Object.extend({
isDone: Ember.computed.empty('todos')
});
let todoList = ToDoList.create({
todos: ['Unit Test', 'Documentation', 'Release']
});
todoList.get('isDone'); // false
todoList.get('todos').clear();
todoList.get('isDone'); // true equal (dependentKey, value) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:265
import { equal } from '@ember/object/computed'; - dependentKey
- String
- value
- String|Number|Object
- returns
- ComputedProperty
- computed property which returns true if the original value for property is equal to the given value.
A computed property that returns true if the provided dependent property is equal to the given value.
Example
let Hamster = Ember.Object.extend({
satisfied: Ember.computed.equal('percentCarrotsEaten', 100)
});
let hamster = Hamster.create();
hamster.get('satisfied'); // false
hamster.set('percentCarrotsEaten', 100);
hamster.get('satisfied'); // true
hamster.set('percentCarrotsEaten', 50);
hamster.get('satisfied'); // false filter (dependentKey, callback) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:267
import { filter } from '@ember/object/computed'; - dependentKey
- String
- callback
- Function
- returns
- Ember.ComputedProperty
- the filtered array
Filters the array by the callback.
The callback method you provide should have the following signature. item is the current item in the iteration. index is the integer index of the current item in the iteration. array is the dependant array itself.
function(item, index, array);
let Hamster = Ember.Object.extend({
remainingChores: Ember.computed.filter('chores', function(chore, index, array) {
return !chore.done;
})
});
let hamster = Hamster.create({
chores: [
{ name: 'cook', done: true },
{ name: 'clean', done: true },
{ name: 'write more unit tests', done: false }
]
});
hamster.get('remainingChores'); // [{name: 'write more unit tests', done: false}] You can also use @each.property in your dependent key, the callback will still use the underlying array:
let Hamster = Ember.Object.extend({
remainingChores: Ember.computed.filter('[email protected]', function(chore, index, array) {
return !chore.get('done');
})
});
let hamster = Hamster.create({
chores: Ember.A([
Ember.Object.create({ name: 'cook', done: true }),
Ember.Object.create({ name: 'clean', done: true }),
Ember.Object.create({ name: 'write more unit tests', done: false })
])
});
hamster.get('remainingChores'); // [{name: 'write more unit tests', done: false}]
hamster.get('chores').objectAt(2).set('done', true);
hamster.get('remainingChores'); // [] filterBy (dependentKey, propertyKey, value) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:333
import { filterBy } from '@ember/object/computed'; - dependentKey
- String
- propertyKey
- String
- value
- *
- returns
- Ember.ComputedProperty
- the filtered array
Filters the array by the property and value
let Hamster = Ember.Object.extend({
remainingChores: Ember.computed.filterBy('chores', 'done', false)
});
let hamster = Hamster.create({
chores: [
{ name: 'cook', done: true },
{ name: 'clean', done: true },
{ name: 'write more unit tests', done: false }
]
});
hamster.get('remainingChores'); // [{ name: 'write more unit tests', done: false }] gt (dependentKey, value) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:300
import { gt } from '@ember/object/computed'; - dependentKey
- String
- value
- Number
- returns
- ComputedProperty
- computed property which returns true if the original value for property is greater than given value.
A computed property that returns true if the provided dependent property is greater than the provided value.
Example
let Hamster = Ember.Object.extend({
hasTooManyBananas: Ember.computed.gt('numBananas', 10)
});
let hamster = Hamster.create();
hamster.get('hasTooManyBananas'); // false
hamster.set('numBananas', 3);
hamster.get('hasTooManyBananas'); // false
hamster.set('numBananas', 11);
hamster.get('hasTooManyBananas'); // true gte (dependentKey, value) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:335
import { gte } from '@ember/object/computed'; - dependentKey
- String
- value
- Number
- returns
- ComputedProperty
- computed property which returns true if the original value for property is greater or equal then given value.
A computed property that returns true if the provided dependent property is greater than or equal to the provided value.
Example
let Hamster = Ember.Object.extend({
hasTooManyBananas: Ember.computed.gte('numBananas', 10)
});
let hamster = Hamster.create();
hamster.get('hasTooManyBananas'); // false
hamster.set('numBananas', 3);
hamster.get('hasTooManyBananas'); // false
hamster.set('numBananas', 10);
hamster.get('hasTooManyBananas'); // true intersect (propertyKey) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:521
import { intersect } from '@ember/object/computed'; - propertyKey
- String
- returns
- Ember.ComputedProperty
- computes a new array with all the duplicated elements from the dependent arrays
A computed property which returns a new array with all the elements two or more dependent arrays have in common.
Example
let obj = Ember.Object.extend({
friendsInCommon: Ember.computed.intersect('adaFriends', 'charlesFriends')
}).create({
adaFriends: ['Charles Babbage', 'John Hobhouse', 'William King', 'Mary Somerville'],
charlesFriends: ['William King', 'Mary Somerville', 'Ada Lovelace', 'George Peacock']
});
obj.get('friendsInCommon'); // ['William King', 'Mary Somerville'] lt (dependentKey, value) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:370
import { lt } from '@ember/object/computed'; - dependentKey
- String
- value
- Number
- returns
- ComputedProperty
- computed property which returns true if the original value for property is less then given value.
A computed property that returns true if the provided dependent property is less than the provided value.
Example
let Hamster = Ember.Object.extend({
needsMoreBananas: Ember.computed.lt('numBananas', 3)
});
let hamster = Hamster.create();
hamster.get('needsMoreBananas'); // true
hamster.set('numBananas', 3);
hamster.get('needsMoreBananas'); // false
hamster.set('numBananas', 2);
hamster.get('needsMoreBananas'); // true lte (dependentKey, value) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:405
import { lte } from '@ember/object/computed'; - dependentKey
- String
- value
- Number
- returns
- ComputedProperty
- computed property which returns true if the original value for property is less or equal than given value.
A computed property that returns true if the provided dependent property is less than or equal to the provided value.
Example
let Hamster = Ember.Object.extend({
needsMoreBananas: Ember.computed.lte('numBananas', 3)
});
let hamster = Hamster.create();
hamster.get('needsMoreBananas'); // true
hamster.set('numBananas', 5);
hamster.get('needsMoreBananas'); // false
hamster.set('numBananas', 3);
hamster.get('needsMoreBananas'); // true map (dependentKey, callback) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:181
import { map } from '@ember/object/computed'; - dependentKey
- String
- callback
- Function
- returns
- Ember.ComputedProperty
- an array mapped via the callback
Returns an array mapped via the callback
The callback method you provide should have the following signature. item is the current item in the iteration. index is the integer index of the current item in the iteration.
function(item, index);
Example
let Hamster = Ember.Object.extend({
excitingChores: Ember.computed.map('chores', function(chore, index) {
return chore.toUpperCase() + '!';
})
});
let hamster = Hamster.create({
chores: ['clean', 'write more unit tests']
});
hamster.get('excitingChores'); // ['CLEAN!', 'WRITE MORE UNIT TESTS!'] mapBy (dependentKey, propertyKey) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:222
import { mapBy } from '@ember/object/computed'; - dependentKey
- String
- propertyKey
- String
- returns
- Ember.ComputedProperty
- an array mapped to the specified key
Returns an array mapped to the specified key.
let Person = Ember.Object.extend({
childAges: Ember.computed.mapBy('children', 'age')
});
let lordByron = Person.create({ children: [] });
lordByron.get('childAges'); // []
lordByron.get('children').pushObject({ name: 'Augusta Ada Byron', age: 7 });
lordByron.get('childAges'); // [7]
lordByron.get('children').pushObjects([{
name: 'Allegra Byron',
age: 5
}, {
name: 'Elizabeth Medora Leigh',
age: 8
}]);
lordByron.get('childAges'); // [7, 5, 8] match (dependentKey, regexp) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:228
import { match } from '@ember/object/computed'; - dependentKey
- String
- regexp
- RegExp
- returns
- ComputedProperty
- computed property which match the original value for property against a given RegExp
A computed property which matches the original value for the dependent property against a given RegExp, returning true if the value matches the RegExp and false if it does not.
Example
let User = Ember.Object.extend({
hasValidEmail: Ember.computed.match('email', /^.+@.+\..+$/)
});
let user = User.create({loggedIn: false});
user.get('hasValidEmail'); // false
user.set('email', '');
user.get('hasValidEmail'); // false
user.set('email', '[email protected]');
user.get('hasValidEmail'); // true max (dependentKey) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:89
import { max } from '@ember/object/computed'; - dependentKey
- String
- returns
- Ember.ComputedProperty
- computes the largest value in the dependentKey's array
A computed property that calculates the maximum value in the dependent array. This will return -Infinity when the dependent array is empty.
let Person = Ember.Object.extend({
childAges: Ember.computed.mapBy('children', 'age'),
maxChildAge: Ember.computed.max('childAges')
});
let lordByron = Person.create({ children: [] });
lordByron.get('maxChildAge'); // -Infinity
lordByron.get('children').pushObject({
name: 'Augusta Ada Byron', age: 7
});
lordByron.get('maxChildAge'); // 7
lordByron.get('children').pushObjects([{
name: 'Allegra Byron',
age: 5
}, {
name: 'Elizabeth Medora Leigh',
age: 8
}]);
lordByron.get('maxChildAge'); // 8 If the types of the arguments are not numbers, they will be converted to numbers and the type of the return value will always be Number. For example, the max of a list of Date objects will be the highest timestamp as a Number. This behavior is consistent with Math.max.
min (dependentKey) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:135
import { min } from '@ember/object/computed'; - dependentKey
- String
- returns
- Ember.ComputedProperty
- computes the smallest value in the dependentKey's array
A computed property that calculates the minimum value in the dependent array. This will return Infinity when the dependent array is empty.
let Person = Ember.Object.extend({
childAges: Ember.computed.mapBy('children', 'age'),
minChildAge: Ember.computed.min('childAges')
});
let lordByron = Person.create({ children: [] });
lordByron.get('minChildAge'); // Infinity
lordByron.get('children').pushObject({
name: 'Augusta Ada Byron', age: 7
});
lordByron.get('minChildAge'); // 7
lordByron.get('children').pushObjects([{
name: 'Allegra Byron',
age: 5
}, {
name: 'Elizabeth Medora Leigh',
age: 8
}]);
lordByron.get('minChildAge'); // 5 If the types of the arguments are not numbers, they will be converted to numbers and the type of the return value will always be Number. For example, the min of a list of Date objects will be the lowest timestamp as a Number. This behavior is consistent with Math.min.
none (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:127
import { none } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which returns true if original value for property is null or undefined.
A computed property that returns true if the value of the dependent property is null or undefined. This avoids errors from JSLint complaining about use of ==, which can be technically confusing.
Example
let Hamster = Ember.Object.extend({
isHungry: Ember.computed.none('food')
});
let hamster = Hamster.create();
hamster.get('isHungry'); // true
hamster.set('food', 'Banana');
hamster.get('isHungry'); // false
hamster.set('food', null);
hamster.get('isHungry'); // true not (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:162
import { not } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which returns inverse of the original value for property
A computed property that returns the inverse boolean value of the original value for the dependent property.
Example
let User = Ember.Object.extend({
isAnonymous: Ember.computed.not('loggedIn')
});
let user = User.create({loggedIn: false});
user.get('isAnonymous'); // true
user.set('loggedIn', true);
user.get('isAnonymous'); // false notEmpty (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:95
import { notEmpty } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which returns true if original value for property is not empty.
A computed property that returns true if the value of the dependent property is NOT null, an empty string, empty array, or empty function.
Example
let Hamster = Ember.Object.extend({
hasStuff: Ember.computed.notEmpty('backpack')
});
let hamster = Hamster.create({ backpack: ['Food', 'Sleeping Bag', 'Tent'] });
hamster.get('hasStuff'); // true
hamster.get('backpack').clear(); // []
hamster.get('hasStuff'); // false oneWay (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:547
import { oneWay } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which creates a one way computed property to the original value for property.
Where computed.alias aliases get and set, and allows for bidirectional data flow, computed.oneWay only provides an aliased get. The set will not mutate the upstream property, rather causes the current property to become the value set. This causes the downstream property to permanently diverge from the upstream property.
Example
let User = Ember.Object.extend({
firstName: null,
lastName: null,
nickName: Ember.computed.oneWay('firstName')
});
let teddy = User.create({
firstName: 'Teddy',
lastName: 'Zeenny'
});
teddy.get('nickName'); // 'Teddy'
teddy.set('nickName', 'TeddyBear'); // 'TeddyBear'
teddy.get('firstName'); // 'Teddy' or (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:480
import { or } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which performs a logical `or` on the values of all the original values for properties.
A computed property which performs a logical or on the original values for the provided dependent properties.
You may pass in more than two properties and even use property brace expansion. The computed property will return the first truthy value or last falsy value just like JavaScript's || operator.
Example
let Hamster = Ember.Object.extend({
readyForRain: Ember.computed.or('hasJacket', 'hasUmbrella'),
readyForBeach: Ember.computed.or('{hasSunscreen,hasUmbrella}')
});
let tomster = Hamster.create();
tomster.get('readyForRain'); // undefined
tomster.set('hasUmbrella', true);
tomster.get('readyForRain'); // true
tomster.set('hasJacket', 'Yes');
tomster.get('readyForRain'); // 'Yes'
tomster.set('hasSunscreen', 'Check');
tomster.get('readyForBeach'); // 'Check' readOnly (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:598
Available since v1.5.0
import { readOnly } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which creates a one way computed property to the original value for property.
Where computed.oneWay provides oneWay bindings, computed.readOnly provides a readOnly one way binding. Very often when using computed.oneWay one does not also want changes to propagate back up, as they will replace the value.
This prevents the reverse flow, and also throws an exception when it occurs.
Example
let User = Ember.Object.extend({
firstName: null,
lastName: null,
nickName: Ember.computed.readOnly('firstName')
});
let teddy = User.create({
firstName: 'Teddy',
lastName: 'Zeenny'
});
teddy.get('nickName'); // 'Teddy'
teddy.set('nickName', 'TeddyBear'); // throws Exception
// throw new Ember.Error('Cannot Set: nickName on: <User:ember27288>' );`
teddy.get('firstName'); // 'Teddy' reads (dependentKey) ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/computed_macros.js:585
import { reads } from '@ember/object/computed'; - dependentKey
- String
- returns
- ComputedProperty
- computed property which creates a one way computed property to the original value for property.
This is a more semantically meaningful alias of computed.oneWay, whose name is somewhat ambiguous as to which direction the data flows.
setDiff (setAProperty, setBProperty) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:575
import { setDiff } from '@ember/object/computed'; - setAProperty
- String
- setBProperty
- String
- returns
- Ember.ComputedProperty
- computes a new array with all the items from the first dependent array that are not in the second dependent array
A computed property which returns a new array with all the properties from the first dependent array that are not in the second dependent array.
Example
let Hamster = Ember.Object.extend({
likes: ['banana', 'grape', 'kale'],
wants: Ember.computed.setDiff('likes', 'fruits')
});
let hamster = Hamster.create({
fruits: [
'grape',
'kale',
]
});
hamster.get('wants'); // ['banana'] sort (itemsKey, sortDefinition) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:677
import { sort } from '@ember/object/computed'; - itemsKey
- String
- sortDefinition
- String or Function
- a dependent key to an array of sort properties (add `:desc` to the arrays sort properties to sort descending) or a function to use when sorting
- returns
- Ember.ComputedProperty
- computes a new sorted array based on the sort property array or callback function
A computed property which returns a new array with all the properties from the first dependent array sorted based on a property or sort function.
The callback method you provide should have the following signature:
function(itemA, itemB);
-
itemAthe first item to compare. -
itemBthe second item to compare.
This function should return negative number (e.g. -1) when itemA should come before itemB. It should return positive number (e.g. 1) when itemA should come after itemB. If the itemA and itemB are equal this function should return 0.
Therefore, if this function is comparing some numeric values, simple itemA - itemB or itemA.get( 'foo' ) - itemB.get( 'foo' ) can be used instead of series of if.
Example
let ToDoList = Ember.Object.extend({
// using standard ascending sort
todosSorting: ['name'],
sortedTodos: Ember.computed.sort('todos', 'todosSorting'),
// using descending sort
todosSortingDesc: ['name:desc'],
sortedTodosDesc: Ember.computed.sort('todos', 'todosSortingDesc'),
// using a custom sort function
priorityTodos: Ember.computed.sort('todos', function(a, b){
if (a.priority > b.priority) {
return 1;
} else if (a.priority < b.priority) {
return -1;
}
return 0;
})
});
let todoList = ToDoList.create({todos: [
{ name: 'Unit Test', priority: 2 },
{ name: 'Documentation', priority: 3 },
{ name: 'Release', priority: 1 }
]});
todoList.get('sortedTodos'); // [{ name:'Documentation', priority:3 }, { name:'Release', priority:1 }, { name:'Unit Test', priority:2 }]
todoList.get('sortedTodosDesc'); // [{ name:'Unit Test', priority:2 }, { name:'Release', priority:1 }, { name:'Documentation', priority:3 }]
todoList.get('priorityTodos'); // [{ name:'Release', priority:1 }, { name:'Unit Test', priority:2 }, { name:'Documentation', priority:3 }] sum (dependentKey) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:73
Available since v1.4.0
import { sum } from '@ember/object/computed'; - dependentKey
- String
- returns
- Ember.ComputedProperty
- computes the sum of all values in the dependentKey's array
A computed property that returns the sum of the values in the dependent array.
union (propertyKey) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:482
import { union } from '@ember/object/computed'; - propertyKey
- String
- returns
- Ember.ComputedProperty
- computes a new array with all the unique elements from the dependent array
A computed property which returns a new array with all the unique elements from one or more dependent arrays.
Example
let Hamster = Ember.Object.extend({
uniqueFruits: Ember.computed.union('fruits', 'vegetables')
});
let hamster = Hamster.create({
fruits: [
'banana',
'grape',
'kale',
'banana',
'tomato'
],
vegetables: [
'tomato',
'carrot',
'lettuce'
]
});
hamster.get('uniqueFruits'); // ['banana', 'grape', 'kale', 'tomato', 'carrot', 'lettuce'] uniq (propertyKey) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:377
import { uniq } from '@ember/object/computed'; - propertyKey
- String
- returns
- Ember.ComputedProperty
- computes a new array with all the unique elements from the dependent array
A computed property which returns a new array with all the unique elements from one or more dependent arrays.
Example
let Hamster = Ember.Object.extend({
uniqueFruits: Ember.computed.uniq('fruits')
});
let hamster = Hamster.create({
fruits: [
'banana',
'grape',
'kale',
'banana'
]
});
hamster.get('uniqueFruits'); // ['banana', 'grape', 'kale'] uniqBy (dependentKey, propertyKey) Ember.ComputedProperty public
| Module: | @ember/object |
|---|
Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:427
import { uniqBy } from '@ember/object/computed'; - dependentKey
- String
- propertyKey
- String
- returns
- Ember.ComputedProperty
- computes a new array with all the unique elements from the dependent array
A computed property which returns a new array with all the unique elements from an array, with uniqueness determined by specific key.
Example
let Hamster = Ember.Object.extend({
uniqueFruits: Ember.computed.uniqBy('fruits', 'id')
});
let hamster = Hamster.create({
fruits: [
{ id: 1, 'banana' },
{ id: 2, 'grape' },
{ id: 3, 'peach' },
{ id: 1, 'banana' }
]
});
hamster.get('uniqueFruits'); // [ { id: 1, 'banana' }, { id: 2, 'grape' }, { id: 3, 'peach' }]
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/2.18/classes/@ember%2Fobject%2Fcomputed/methods