Class: SC.Reducers
Defined in: enumerable.js
Instance Methods
- enumerableContentDidChange(start, length, deltas)
- reduceAverage(previousValue, item, index, reducerProperty, reducerProperty)
- reducedProperty(key, value, generateProperty)
- reduceMax(previousValue, item, index, reducerProperty, reducerProperty)
- reduceMaxObject(previousValue, item, index, reducerProperty, reducerProperty)
- reduceMin(previousValue, item, index, reducerProperty, reducerProperty)
- reduceMinObject(previousValue, item, index, reducerProperty, reducerProperty)
- reduceSum(previousValue, item, index, reducerProperty, reducerProperty)
Instance Method Detail
Invoke this method when the contents of your enumerable has changed.
This will notify any observers watching for content changes. If you are
implementing an ordered enumerable (such as an Array), also pass the
start and length values so that it can be used to notify range observers.
Passing start and length values will also ensure that the computed
properties firstObject
and lastObject
are updated.
- Parameters:
- start Number Optional
- start offset for the content change
- length Number Optional
- length of change
- deltas Number Optional
- if you added or removed objects, the delta change
- Returns:
- Object
- receiver
Reduces an enumerable to the average of the items in the enumerable. If
reducerProperty
is passed, it will reduce that property. Otherwise, it will
reduce the item itself.
- Parameters:
- previousValue Object
- The previous value in the enumerable
- item Object
- The current value in the enumerable
- index Number
- The index of the current item in the enumerable
- reducerProperty String
- (Optional) The property in the enumerable being reduced
- reducerProperty
- Returns:
- Object
- reduced value
Call this method from your unknownProperty
() handler to implement
automatic reduced properties. A reduced property is a property that
collects its contents dynamically from your array contents. Reduced
properties always begin with "@". Getting this property will call
reduce() on your array with the function matching the key name as the
processor.
The return value of this will be either the return value from the
reduced property or undefined, which means this key is not a reduced
property. You can call this at the top of your unknownProperty
handler
like so:
unknownProperty
: function (key, value) {
var ret = this.handleReduceProperty(key, value);
if (ret === undefined) {
// process like normal
}
}
- Parameters:
- previousValue Object
- The previous value in the enumerable
- item Object
- The current value in the enumerable
- index Number
- The index of the current item in the enumerable
- reducerProperty String
- (Optional) The property in the enumerable being reduced
- reducerProperty
- Returns:
- Object
- reduced value
Reduces an enumerable to the max of the items in the enumerable. If
reducerProperty
is passed, it will reduce that property. Otherwise, it will
reduce the item itself.
- Parameters:
- previousValue Object
- The previous value in the enumerable
- item Object
- The current value in the enumerable
- index Number
- The index of the current item in the enumerable
- reducerProperty String
- (Optional) The property in the enumerable being reduced
- reducerProperty
- Returns:
- Object
- reduced value
Reduces an enumerable to the min of the items in the enumerable. If
reducerProperty
is passed, it will reduce that property. Otherwise, it will
reduce the item itself.
- Parameters:
- previousValue Object
- The previous value in the enumerable
- item Object
- The current value in the enumerable
- index Number
- The index of the current item in the enumerable
- reducerProperty String
- (Optional) The property in the enumerable being reduced
- reducerProperty
- Returns:
- Object
- reduced value
Reduces an enumerable to the max of the items in the enumerable. If
reducerProperty
is passed, it will reduce that property. Otherwise, it will
reduce the item itself.
- Parameters:
- previousValue Object
- The previous value in the enumerable
- item Object
- The current value in the enumerable
- index Number
- The index of the current item in the enumerable
- reducerProperty String
- (Optional) The property in the enumerable being reduced
- reducerProperty
- Returns:
- Object
- reduced value
Reduces an enumerable to the sum of the items in the enumerable. If
reducerProperty
is passed, it will reduce that property. Otherwise, it will
reduce the item itself.
- Parameters:
- previousValue Object
- The previous value in the enumerable
- item Object
- The current value in the enumerable
- index Number
- The index of the current item in the enumerable
- reducerProperty String
- (Optional) The property in the enumerable being reduced
- reducerProperty
- Returns:
- Object
- reduced value