Skip to content

Commit 5f4388f

Browse files
committed
transition refactor
1 parent 3392623 commit 5f4388f

File tree

7 files changed

+255
-288
lines changed

7 files changed

+255
-288
lines changed

component.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
"src/parsers/path.js",
6262
"src/parsers/template.js",
6363
"src/parsers/text.js",
64-
"src/transition/css.js",
6564
"src/transition/index.js",
66-
"src/transition/js.js",
65+
"src/transition/queue.js",
66+
"src/transition/transition.js",
6767
"src/util/debug.js",
6868
"src/util/dom.js",
6969
"src/util/env.js",

src/directives/transition.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var _ = require('../util')
2+
var Transition = require('../transition/transition')
23

34
module.exports = {
45

@@ -12,19 +13,15 @@ module.exports = {
1213
},
1314

1415
update: function (id, oldId) {
16+
var el = this.el
1517
var vm = this.el.__vue__ || this.vm
16-
this.el.__v_trans = {
17-
id: id,
18-
// resolve the custom transition functions now
19-
// so the transition module knows this is a
20-
// javascript transition without having to check
21-
// computed CSS.
22-
hooks: _.resolveAsset(vm.$options, 'transitions', id)
23-
}
18+
var hooks = _.resolveAsset(vm.$options, 'transitions', id)
19+
id = id || 'v'
20+
el.__v_trans = new Transition(el, id, hooks, vm)
2421
if (oldId) {
25-
_.removeClass(this.el, oldId + '-transition')
22+
_.removeClass(el, oldId + '-transition')
2623
}
27-
_.addClass(this.el, (id || 'v') + '-transition')
24+
_.addClass(el, id + '-transition')
2825
}
2926

3027
}

src/transition/apply.js

Lines changed: 0 additions & 272 deletions
This file was deleted.

src/transition/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var _ = require('../util')
2-
var applyTransition = require('./apply')
32

43
/**
54
* Append with transition.
@@ -107,9 +106,9 @@ exports.blockRemove = function (start, end, vm) {
107106
*/
108107

109108
var apply = exports.apply = function (el, direction, op, vm, cb) {
110-
var transData = el.__v_trans
109+
var transition = el.__v_trans
111110
if (
112-
!transData ||
111+
!transition ||
113112
!vm._isCompiled ||
114113
// if the vm is being manipulated by a parent directive
115114
// during the parent's compilation phase, skip the
@@ -120,5 +119,6 @@ var apply = exports.apply = function (el, direction, op, vm, cb) {
120119
if (cb) cb()
121120
return
122121
}
123-
applyTransition(el, direction, op, transData, vm, cb)
122+
var action = direction > 0 ? 'enter' : 'leave'
123+
transition[action](op, cb)
124124
}

src/transition/queue.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var _ = require('../util')
2+
var queue = []
3+
var queued = false
4+
5+
exports.push = function (job) {
6+
queue.push(job)
7+
if (!queued) {
8+
queued = true
9+
_.nextTick(flush)
10+
}
11+
}
12+
13+
/**
14+
* Flush the queue, and do one forced reflow before
15+
* triggering transitions.
16+
*/
17+
18+
function flush () {
19+
// Force layout
20+
var f = document.documentElement.offsetHeight
21+
for (var i = 0; i < queue.length; i++) {
22+
queue[i]()
23+
}
24+
queue = []
25+
queued = false
26+
// dummy return, so js linters don't complain about
27+
// unused variable f
28+
return f
29+
}

0 commit comments

Comments
 (0)