backbone
backbone copied to clipboard
Change to splice method so it is observable
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.
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
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?
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.