Open Raynos opened 10 years ago
For sanity computedFilter()
and computedMap()
should not return mutable observ-array
instances. They should return computed read only arrays.
I think it is better with a proxy on top, a layer that can be added or removed ;) keep it flexible...
use freeze
on array I guess :)
I will look at this tmrw, you are most welcome to do a head start if you got a few mins or hours ;) I can see it would make a very nice addition indeed!
Also check out: http://emberjs.com/api/classes/Ember.ArrayProxy.html
and especially http://emberjs.com/api/classes/Ember.MutableArray.html
addArrayObserver (target, opts) Ember.Array
Inherited from Ember.Array packages/ember-runtime/lib/mixins/array.js:330
Adds an array observer to the receiving array. The array observer object normally must implement two methods:
arrayWillChange(observedObj, start, removeCount, addCount)
- This method will be called just before the array is modified.
arrayDidChange(observedObj, start, removeCount, addCount)
- This method will be called just after the array is modified.
This way it keeps track of the index where change was made and how many elements were added removed starting at that index. Pretty clever IMO ;)
Currently when you call
map()
andfilter()
on an array you get a static computed copy.This works fine if you never add or remove items from
list
anddoubles
will performantly only do updates to the values that actually update inlist
.However we want to support a
computedFilter
andcomputedMap
that listens to all changes on the array including additions and removals.See knockout-projections for an implementation of
computedFilter
andcomputedMap
for knockoutJS.I have a previous buggy / untested implementation of
computedFilter
herecc @Matt-Esch would appreciate advice on performance