Handling observableArrays which share the same array instance

24 views
Skip to first unread message

Douglas

unread,
Jan 23, 2012, 11:19:22 AM1/23/12
to knock...@googlegroups.com
Hi All,

I've just run into a bug in my web app where I ended up with two observableArrays which depend on the same base array instance. To see what I mean, here is a cut down sample:

http://jsfiddle.net/pVh3Z/ 

What I expected to happen was for "a" to disappear from both lists, but since "a" had already been removed from the underlying array after first.remove, an orphan UI element was left in the view for the second observable array. It was doubly confusing because inspecting the second observableArray did indeed show that the element had been removed...

My solution was to add ".slice(0)" before setting the value of the second array. I'm wondering if this sort of problem is worth a fix in the library, or if it is too much of an edge case.

Would it make sense to always clone the array passed into the observableArray setter? Or could the array be marked so that an error can be thrown if two observableArrays reference the same underlying array?

Thanks,
Douglas

Reply all
Reply to author
Forward
0 new messages