HotDrink / hotdrink

JavaScript MVVM library with support for multi-way dependencies and generic, rich UI behaviors.
http://hotdrink.github.io/hotdrink/
58 stars 9 forks source link

hd.list proxy functions #36

Closed philipvr closed 12 years ago

philipvr commented 12 years ago

Knockout has implemented the standard array functions for their ko.observableArray such as push, pop, unshift, shift, reverse, sort, etc. (see ko documentation).

Hotdrink only has push, pop, remove for hd.list. I have already implemented removeAll and sort. Should I continue to implement these functions so that Hotdrink is on par with Knockout in this area?

thejohnfreeman commented 12 years ago

Yes, all reasonable methods will need to be implemented eventually, but Knockout is not our guide here. Consult MDN for standard array methods[^1] and provide the same interface.

We want to provide some simple helpers beyond the standard interface. I implemented remove already. Instead of removeAll, our method should be called clear. Perhaps add an isEmpty. Consult the other helpers I added to Array for more ideas: has, setUnion, setIntersect, setInsert, etc.

[^1] Note that toSource is non-standard.

philipvr commented 12 years ago

I implemented the removeAll function that takes an array and removes the items contained in the array:

myObservableArray.removeAll(['Chad', 132, undefined]) removes all values that equal 'Chad', 123, or undefined and returns them as an array

My removeAll function does not remove all elements from the array when no argument is passed (I didn't implement this yet). I agree that removeAll is not the best name for this function.

thejohnfreeman commented 12 years ago

That functionality should be folded into remove. Just have it iterate over all arguments instead of taking a single argument.