Class: SC.Reducers

Defined in: enumerable.js

Instance Methods

Instance Method Detail

enumerableContentDidChange(start, length, deltas)

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
reduceAverage(previousValue, item, index, reducerProperty, reducerProperty)

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
reducedProperty(key, value, generateProperty)

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:
key String
the reduce property key
value Object
a value or undefined.
generateProperty Boolean
only set to false if you do not want an optimized computed property handler generated for this. Not common.
Returns:
Object
the reduced property or undefined
reduceMax(previousValue, item, index, reducerProperty, reducerProperty)
Reducer for @max reduced property.
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
reduceMaxObject(previousValue, item, index, reducerProperty, reducerProperty)

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
reduceMin(previousValue, item, index, reducerProperty, reducerProperty)

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
reduceMinObject(previousValue, item, index, reducerProperty, reducerProperty)

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
reduceSum(previousValue, item, index, reducerProperty, reducerProperty)

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
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:21 GMT-0600 (CST)