hay / stapes

the Javascript MVC microframework that does just enough
http://hay.github.io/stapes
MIT License
443 stars 54 forks source link

better way to handle data append than using get/set? #34

Closed bitinn closed 11 years ago

bitinn commented 11 years ago

I recently started to use stapes.js with rivets.js (data-binding) on a small project, one of the common tasks is to append an array of objects (from json response) to an existing array of objects (say for infinite scroll).

In order for rivets to update data-binding automatically and keep objects in order (so we can iteration it using input order), I copy the existing array and concat it with new array.

var old = self.get('items');
var append;
if(old)
    append = old.concat(items);
else
    append = items;

self.set('items', append);

Is there a better way using push (that guarantee orders)? any performance impact when setting large array?

hay commented 11 years ago

Hi bitiin. Thanks for your question. Would you be so kind to make an example, for example using something like jsfiddle.net? I can take a look at it then. Also, i would be interested in seeing how rivets and stapes work together!

bitinn commented 11 years ago

rivets does have a (well-hidden) Todo example with older stapes: http://bl.ocks.org/mikeric/3345763, it use an adapter to listen for change event emitted by stapes.

I mainly use knockout.js in the past, and their obserable array implementation is what I normally use for case described above, their doc might serve better explanation - http://knockoutjs.com/documentation/observableArrays.html

also see discussion regarding this on rivets end: https://github.com/mikeric/rivets/issues/52, I do think stapes + rivets will be great, so please keep up the good work!