-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: #4265 prevent double update when bind to object #8992
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
Changes from 2 commits
bfeda78
1cc1280
0341e0b
841b641
0e5e471
34dcc5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,10 +21,13 @@ import { transition_in } from './transitions.js'; | |
|
|
||
| /** @returns {void} */ | ||
| export function bind(component, name, callback) { | ||
| const index = component.$$.props[name]; | ||
| if (index !== undefined) { | ||
| component.$$.bound[index] = callback; | ||
| callback(component.$$.ctx[index]); | ||
| const i = component.$$.props[name]; | ||
| if (i !== undefined) { | ||
| let dirty = false; | ||
| if (component.$$.bound[i]) dirty = true; | ||
| component.$$.bound[i] = callback; | ||
| // first binding call, if child value is not yet dirty, skip to prevent unnecessary backflow | ||
| callback(component.$$.ctx[i], /** skip_binding */ !dirty); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Case 2: Child does not touch passed-in prop value |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -125,8 +128,9 @@ export function init( | |
| ? instance(component, options.props || {}, (i, ret, ...rest) => { | ||
| const value = rest.length ? rest[0] : ret; | ||
| if ($$.ctx && not_equal($$.ctx[i], ($$.ctx[i] = value))) { | ||
| if (!$$.skip_bound && $$.bound[i]) $$.bound[i](value); | ||
| if (!$$.skip_bound && is_function($$.bound[i])) $$.bound[i](value); | ||
| if (ready) make_dirty(component, i); | ||
| else $$.bound[i] = true; // dirty flag consumed in bind() | ||
|
||
| } | ||
| return ret; | ||
| }) | ||
|
|
||
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.
if (!#skip_binding || ${lhs} !== #value)guard prevents the unnecessary backflow of case 2, also${lhs} !== #valuecheck allows backflow for case 1 and 4.1.Case 2: Child does not touch passed-in prop value, regardless it's primitive or object, backflow is unnecessary
Case 1 and 4.1: Child value is referentially different from Parent value