backbone icon indicating copy to clipboard operation
backbone copied to clipboard

Change to splice method so it is observable

Open robinchesterman opened this issue 8 years ago • 3 comments

The existing splice method uses the indexer:

array[i + at] = insert[i]

This is not a natively observable change using modern Javascript Reflection APIs.

This PR changes the method to achieve the same effect but using native Array.splice.

This may be useful when using Backbone with other frameworks e.g. it may be desirable to use Backbone modelling for the excellent collection methods and REST APIs, but Aurelia or Angular for UI data-binding.

The latter frameworks can't observe changes on collection.models array if they're done with the indexer. Splice is observable.

robinchesterman avatar May 03 '16 20:05 robinchesterman

Splice was added in https://github.com/jashkenas/backbone/pull/3663. I'll defer to @jridgewell on this one. If this does get in, I'd rather remove the internal splice function all togehter

megawac avatar May 06 '16 17:05 megawac

I removed splice because of its horrible performance in loops (adding an array of models at a particular index).

How is #splice observable bot indexed sets aren't?

jridgewell avatar May 06 '16 17:05 jridgewell

I'm in favor of this change, but the performance claim needs quantification before the change can be made. By "quantification", I mean something a little more serious than a nanobenchmark on jsperf. Not to mention that jsperf seems to be broken.

jgonggrijp avatar Dec 18 '21 02:12 jgonggrijp