Skip to content
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

Merged
merged 5 commits into from
Nov 19, 2019

Conversation

bmomberger-bitovi
Copy link
Contributor

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.

Copy link
Contributor

@phillipskevin phillipskevin left a 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.

@@ -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) {
Copy link
Contributor

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it seems not :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them.

Copy link
Contributor

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 😢

@bmomberger-bitovi bmomberger-bitovi merged commit de267ba into master Nov 19, 2019
@bmomberger-bitovi bmomberger-bitovi deleted the convert-patch-inserts branch November 19, 2019 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants