(Reduce)Computed
functional big data transclusion in the browser
@jonnii
What is the best
feature of ember?
Routing?
Maybe...
Ember.Select?
Hahahahahaha. NO.
Computed Properties!!
Seriously, they are magic.
You know you can do this...
Did you know you can do this?
Computed Properties just reduced.
This is how I discovered reduce computed...
What is reduce computed?
A reduce computed is a computed property which
observes the state of an array and reduces it
into a single value...
e.g.
Ember.computed.min
Ember.computed.max
It's the reduce part of map reduce. a.k.a Big Data.
Reduce Computed
- initialValue
- options
- addedItem
- removedItem
Ember.computed.max = function (dependentKey) {
return Ember.reduceComputed.call(null, dependentKey, {
initialValue: -Infinity,
addedItem: function (accumulatedValue, item, changeMeta, instanceMeta) {
return Math.max(accumulatedValue, item);
},
removedItem: function (accumulatedValue, item, changeMeta, instanceMeta) {
if (item < accumulatedValue) {
return accumulatedValue;
}
}
});
};
The secret sauce...
xxItem: function (accumulatedValue, item, changeMeta, instanceMeta) {
... magic ...
},
changeMeta
index
item
arrayChanged
property
instanceMeta
A scratch pad for storing
reduce computed state
Example Sum/Avg
Array Computed
Same as reduce computed except:
- Result is an array
- Result is kept up to date
For:
- Filtering
- Sorting
Group Example
What next?
Feature actively being worked on
Someone please rewrite Ember.Select
Plugs
Code Now
http://codenow.org/
I'm hiring...
ReduceComputed
By Jonathan Goldman
ReduceComputed
- 2,435