-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispatch patches with converted items on push/unshift/splice #73
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good. It would be good to test all of the cases like we are in https://github.com/canjs/can-observable-array/blob/master/test/array-test.js#L340.
…le-array into convert-patch-inserts
@@ -133,4 +134,62 @@ module.exports = function() { | |||
arr[0] = { num: 6 }; | |||
assert.ok(arr[0] instanceof MyObject, "Converts on an index setter"); | |||
}); | |||
|
|||
QUnit.test("patches dispatched with converted members", function (assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it seems not :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked the other test 😢
Before this PR, patches events were being dispatched with the data being added into the array pre-conversion. So if the observable array has
static get items()
defined, it will correctly push converted items into the array, but dispatch a patch with the original objects instead.Because can-view-live uses the data in patches to keep list items in sync, this was causing issues with live binding.
This PR converts items to be added into the array in the mutation method shim, a pull up from the handlers for each individual array method, and now at the same level where the patches dispatch is being ordered. This ensures that any patch listener has the same data as the array itself.