-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto cache inline prop literals to avoid child re-render
- Loading branch information
Showing
6 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/core/instance/render-helpers/create-inline-computed.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* @flow */ | ||
|
||
import { noop } from 'shared/util' | ||
import Watcher from 'core/observer/watcher' | ||
|
||
/** | ||
* This runtime helper creates an inline computed property for component | ||
* props that contain object or array literals. The caching ensures the same | ||
* object/array is returned unless the value has indeed changed, thus avoiding | ||
* the child component to always re-render when comparing props values. | ||
* | ||
* Installed to the instance as _a, requires special handling in parser that | ||
* transforms the following | ||
* <foo :bar="{ a: 1 }"/> | ||
* to: | ||
* <foo :bar="_a(0, function(){return { a: 1 }})" | ||
*/ | ||
export function createInlineComputed (id: string, getter: Function): any { | ||
const vm: Component = this | ||
const watchers = vm._inlineComputed || (vm._inlineComputed = {}) | ||
const cached = watchers[id] | ||
if (cached) { | ||
return cached.value | ||
} else { | ||
watchers[id] = new Watcher(vm, getter, noop, { sync: true }) | ||
return watchers[id].value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
996eb00
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 the inline computed watchers need to have a teardown as well or will the Garbage Collector pick them up automatically?
996eb00
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.
Yeah, there are some neglected issues with this strategy. I'm reverting the change for now.
996eb00
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.
@yyx990803 we had a build with buggy behavior (links created inside of a v-for weren't properly resolving to the appropriate target) when built on 2.5.12 which had this code. This bug fixed itself when we built against 2.5.13 after this had been resolved.
Our code which started misbehaving:
Let me know if we can provide any more useful information to help add a test case to cover this in the future.
As an aside: it was a bit tough to track this down looking through the commit log. Is there a changelog where we could find a description of changes like this for future reference?
Thanks!