Skip to content

Commit

Permalink
Revert "feat: auto cache inline prop literals to avoid child re-render"
Browse files Browse the repository at this point in the history
This reverts commit 996eb00.
  • Loading branch information
yyx990803 committed Dec 19, 2017
1 parent ec2c48c commit aac7634
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 83 deletions.
3 changes: 0 additions & 3 deletions flow/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ declare interface Component {
_staticTrees: ?Array<VNode>; // v-once cached trees
_hasHookEvent: boolean;
_provided: ?Object;
_inlineComputed: ?{ [key: string]: Watcher }; // inline computed watchers for literal props
// _virtualComponents?: { [key: string]: Component };

// private methods
Expand Down Expand Up @@ -131,8 +130,6 @@ declare interface Component {
_k: (eventKeyCode: number, key: string, builtInAlias?: number | Array<number>, eventKeyName?: string) => ?boolean;
// resolve scoped slots
_u: (scopedSlots: ScopedSlotsData, res?: Object) => { [key: string]: Function };
// create / return value from inline computed
_a: (id: number, getter: Function) => any;

// SSR specific
_ssrNode: Function;
Expand Down
15 changes: 0 additions & 15 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@ const argRE = /:(.*)$/
export const bindRE = /^:|^v-bind:/
const modifierRE = /\.[^.]+/g

const literalValueRE = /^(\{.*\}|\[.*\])$/

const decodeHTMLCached = cached(he.decode)

// configurable state
export let warn: any
let literalPropId
let delimiters
let transforms
let preTransforms
let postTransforms
let platformIsPreTag
let platformMustUseProp
let platformIsReservedTag
let platformGetTagNamespace

type Attr = { name: string; value: string };
Expand Down Expand Up @@ -70,11 +66,9 @@ export function parse (
options: CompilerOptions
): ASTElement | void {
warn = options.warn || baseWarn
literalPropId = 0

platformIsPreTag = options.isPreTag || no
platformMustUseProp = options.mustUseProp || no
platformIsReservedTag = options.isReservedTag || no
platformGetTagNamespace = options.getTagNamespace || no

transforms = pluckModuleFunction(options.modules, 'transformNode')
Expand Down Expand Up @@ -544,15 +538,6 @@ function processAttrs (el) {
)
}
}
// optimize literal values in component props by wrapping them
// in an inline watcher to avoid unnecessary re-renders
if (
!platformIsReservedTag(el.tag) &&
el.tag !== 'slot' &&
literalValueRE.test(value.trim())
) {
value = `_a(${literalPropId++},function(){return ${value}})`
}
if (isProp || (
!el.component && platformMustUseProp(el.tag, el.attrsMap.type, name)
)) {
Expand Down
28 changes: 0 additions & 28 deletions src/core/instance/render-helpers/create-inline-computed.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/core/instance/render-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { bindObjectProps } from './bind-object-props'
import { renderStatic, markOnce } from './render-static'
import { bindObjectListeners } from './bind-object-listeners'
import { resolveScopedSlots } from './resolve-slots'
import { createInlineComputed } from './create-inline-computed'

export function installRenderHelpers (target: any) {
target._o = markOnce
Expand All @@ -28,5 +27,4 @@ export function installRenderHelpers (target: any) {
target._e = createEmptyVNode
target._u = resolveScopedSlots
target._g = bindObjectListeners
target._a = createInlineComputed
}
1 change: 0 additions & 1 deletion src/core/instance/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function proxy (target: Object, sourceKey: string, key: string) {

export function initState (vm: Component) {
vm._watchers = []
vm._inlineComputed = null
const opts = vm.$options
if (opts.props) initProps(vm, opts.props)
if (opts.methods) initMethods(vm, opts.methods)
Expand Down
34 changes: 0 additions & 34 deletions test/unit/features/options/props.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,38 +512,4 @@ describe('Options props', () => {
expect(`"${attr}" is a reserved attribute`).toHaveBeenWarned()
})
})

it('should not trigger re-render on non-changed inline literals', done => {
const updated = jasmine.createSpy('updated')
const vm = new Vue({
data: {
n: 1,
m: 1
},
template: `
<div id="app">
{{ n }} {{ m }} <foo :a="{ n: 1 }" :b="{ n: n }"/>
</div>
`,
components: {
foo: {
props: ['a', 'b'],
updated,
template: `<div>{{ a.n }} {{ b.n }}</div>`
}
}
}).$mount()

expect(vm.$el.textContent).toContain('1 1 1 1')
vm.n++ // literals that actually contain changed reactive data should trigger update
waitForUpdate(() => {
expect(vm.$el.textContent).toContain('2 1 1 2')
expect(updated.calls.count()).toBe(1)
}).then(() => {
vm.m++ // changing data that does not affect any literals should not trigger update
}).then(() => {
expect(vm.$el.textContent).toContain('2 2 1 2')
expect(updated.calls.count()).toBe(1)
}).then(done)
})
})

0 comments on commit aac7634

Please sign in to comment.