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

do not proxify objects that are values of non-patchable array properties #47

Merged
merged 6 commits into from Aug 6, 2019

Conversation

warpech
Copy link
Contributor

@warpech warpech commented Jul 29, 2019

because such problem happens in Vue 2 and it results in an invalid patch. See: vuejs/vue#427, vuejs/vue#9259

@warpech warpech requested a review from tomalec July 29, 2019 13:14
because such problem happens in Vue 2 and it results in an invalid patch. See: vuejs/vue#427, vuejs/vue#9259
Copy link
Member

@tomalec tomalec left a comment

Choose a reason for hiding this comment

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

Do we plan to revert this change eventually, once Vue 3 would become mature enough?

test/spec/proxySpec.js Outdated Show resolved Hide resolved
src/jsonpatcherproxy.js Show resolved Hide resolved
as proposed by @tomalec in PR review #47 (review)
@warpech
Copy link
Contributor Author

warpech commented Jul 30, 2019

All addressed. Pleasee re-review.

Do we plan to revert this change eventually, once Vue 3 would become mature enough?

I don't think so. This change is useful general and the problem is not specific only to Vue. It just happens that Vue 2 is a very high profile framework that exhibits this problem.

// if the new value is an object, make sure to watch it
if (
newValue &&
typeof newValue == 'object' &&
!instance._treeMetadataMap.has(newValue)
) {
instance._parenthoodMap.set(newValue, { parent: tree, key });
newValue = instance._proxifyTreeRecursively(tree, newValue, key);
if (isTreeAnArray && !Number.isInteger(+key.toString())) {
Copy link
Member

Choose a reason for hiding this comment

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

cosmetic: Just for my personal readability, we could also create a const isArrayProperty = isTreeAnArray && !Number.isInteger(+key.toString()) not to repeat it here and at l.139. Slightly DRYier vs. one const variable less. If you find it readable and better this way, let's keep it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@tomalec tomalec left a comment

Choose a reason for hiding this comment

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

LGTM

# Conflicts:
#	test/spec/proxySpec.js
because the last merge had a conflict incorrectly resolved automatically by p4merge
@warpech warpech merged commit e0592b6 into master Aug 6, 2019
@warpech warpech deleted the fix-vue-problem-with-arrays branch August 6, 2019 13: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

2 participants