Explorar o código

resolve js transition effect during compilation rather than at transition

Evan You %!s(int64=11) %!d(string=hai) anos
pai
achega
8a37764587

+ 3 - 1
src/directives/transition.js

@@ -5,7 +5,9 @@ module.exports = {
 
 
   bind: function () {
   bind: function () {
     this.el.__v_trans = {
     this.el.__v_trans = {
-      id: this.expression
+      id: this.expression,
+      // resolve the custom transition functions now
+      fns: this.vm.$options.transitions[this.expression]
     }
     }
   }
   }
 
 

+ 1 - 1
src/transition/index.js

@@ -122,7 +122,7 @@ var apply = exports.apply = function (el, direction, op, vm, cb) {
     return
     return
   }
   }
   // determine the transition type on the element
   // determine the transition type on the element
-  var jsTransition = vm.$options.transitions[transData.id]
+  var jsTransition = transData.fns
   if (jsTransition) {
   if (jsTransition) {
     // js
     // js
     applyJSTransition(
     applyJSTransition(

+ 11 - 2
test/unit/specs/directives/transition_spec.js

@@ -4,14 +4,23 @@ var def = require('../../../../src/directives/transition')
 if (_.inBrowser) {
 if (_.inBrowser) {
   describe('v-transition', function () {
   describe('v-transition', function () {
 
 
-    it('should save the transition id as data', function () {
+    it('should save the transition id and custom functions as data', function () {
+      var fns = {}
       var dir = {
       var dir = {
         el: document.createElement('div'),
         el: document.createElement('div'),
         expression: 'test',
         expression: 'test',
-        bind: def.bind
+        bind: def.bind,
+        vm: {
+          $options: {
+            transitions: {
+              test: fns
+            }
+          }
+        }
       }
       }
       dir.bind()
       dir.bind()
       expect(dir.el.__v_trans.id).toBe('test')
       expect(dir.el.__v_trans.id).toBe('test')
+      expect(dir.el.__v_trans.fns).toBe(fns)
     })
     })
 
 
   })
   })

+ 3 - 8
test/unit/specs/transition/transition_spec.js

@@ -305,18 +305,13 @@ if (_.inBrowser && !_.isIE9) {
       var el, vm, op, cb, def, emitter
       var el, vm, op, cb, def, emitter
       beforeEach(function () {
       beforeEach(function () {
         emitter = {}
         emitter = {}
+        def = {}
         el = document.createElement('div')
         el = document.createElement('div')
-        el.__v_trans = { id: 'test' }
+        el.__v_trans = { id: 'test', fns: def }
         document.body.appendChild(el)
         document.body.appendChild(el)
         op = jasmine.createSpy('js transition op')
         op = jasmine.createSpy('js transition op')
         cb = jasmine.createSpy('js transition cb')
         cb = jasmine.createSpy('js transition cb')
-        def = {}
-        vm = new Vue({
-          el: el,
-          transitions: {
-            test: def
-          }
-        })
+        vm = new Vue({ el: el })
       })
       })
 
 
       afterEach(function () {
       afterEach(function () {