From 6209102bd7ad40b85add40b04d140a939fcdeb2a Mon Sep 17 00:00:00 2001 From: "Filipe T. Amaral" Date: Thu, 24 Jan 2019 23:30:01 -0200 Subject: [PATCH 1/2] fix(transition): Explicitly disable appear The @appear hook is being invoked when appear is not specified or is falsy. This change make it possible to dynamically disable it by setting :appear="false" when needed. --- .../web/runtime/components/transition.js | 17 ++++++++++--- .../features/transition/transition.spec.js | 24 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/platforms/web/runtime/components/transition.js b/src/platforms/web/runtime/components/transition.js index 84fe82984a1..0901fc304d7 100644 --- a/src/platforms/web/runtime/components/transition.js +++ b/src/platforms/web/runtime/components/transition.js @@ -40,6 +40,15 @@ function getRealChild (vnode: ?VNode): ?VNode { } } +function isAttrDisabled (k: string): boolean { + var data: Object = this; + const attr = data[camelize(k)] + return typeof attr == "undefined" || + typeof attr !== "undefined" && + (typeof attr === "boolean" && attr || + typeof attr === "string" && attr == "false") +} + export function extractTransitionData (comp: Component): Object { const data = {} const options: ComponentOptions = comp.$options @@ -49,9 +58,11 @@ export function extractTransitionData (comp: Component): Object { } // events. // extract listeners and pass them directly to the transition methods - const listeners: ?Object = options._parentListeners - for (const key in listeners) { - data[camelize(key)] = listeners[key] + const listeners: Object = options._parentListeners || {} + // remove the listeners that are explicitily disabled + const listenerKeys: Array = Object.keys(listeners).filter(isAttrDisabled, data) + for (let i = 0; i < listenerKeys.length; i++) { + data[camelize(listenerKeys[i])] = listeners[listenerKeys[i]] } return data } diff --git a/test/unit/features/transition/transition.spec.js b/test/unit/features/transition/transition.spec.js index 2ecf80b854d..888fb28f4b3 100644 --- a/test/unit/features/transition/transition.spec.js +++ b/test/unit/features/transition/transition.spec.js @@ -769,6 +769,30 @@ if (!isIE9) { }).then(done) }) + it('appear: false', done => { + let next + const vm = new Vue({ + template: ` +
+ +
foo
+
+
+ `, + data: { ok: true }, + methods: { + appear: (el, cb) => { + next = cb + } + } + }).$mount(el) + + waitForUpdate(() => { + expect(vm.$el.children[0].className).toBe('test') + expect(next).toBeUndefined() + }).then(done) + }) + it('transition on SVG elements', done => { const vm = new Vue({ template: ` From e95fd3195e902ba03f52c86222b3a15e0abfcf66 Mon Sep 17 00:00:00 2001 From: "Filipe T. Amaral" Date: Fri, 25 Jan 2019 09:51:50 -0200 Subject: [PATCH 2/2] fix(transition): Improve active attributes filter implementation --- src/platforms/web/runtime/components/transition.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/platforms/web/runtime/components/transition.js b/src/platforms/web/runtime/components/transition.js index 0901fc304d7..171ea28ca32 100644 --- a/src/platforms/web/runtime/components/transition.js +++ b/src/platforms/web/runtime/components/transition.js @@ -40,13 +40,9 @@ function getRealChild (vnode: ?VNode): ?VNode { } } -function isAttrDisabled (k: string): boolean { - var data: Object = this; - const attr = data[camelize(k)] - return typeof attr == "undefined" || - typeof attr !== "undefined" && - (typeof attr === "boolean" && attr || - typeof attr === "string" && attr == "false") +function activeAttr (k: string): boolean { + // assuming active if undefined + return this[camelize(k)] === undefined || this[camelize(k)] === true } export function extractTransitionData (comp: Component): Object { @@ -60,7 +56,7 @@ export function extractTransitionData (comp: Component): Object { // extract listeners and pass them directly to the transition methods const listeners: Object = options._parentListeners || {} // remove the listeners that are explicitily disabled - const listenerKeys: Array = Object.keys(listeners).filter(isAttrDisabled, data) + const listenerKeys: Array = Object.keys(listeners).filter(activeAttr, data) for (let i = 0; i < listenerKeys.length; i++) { data[camelize(listenerKeys[i])] = listeners[listenerKeys[i]] }