Skip to content

Commit f9bebc7

Browse files
committed
fix enteredView/leftView
1 parent 9ec0259 commit f9bebc7

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

src/transition.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ var endEvent = sniffTransitionEndEvent(),
2121
* 1 = enter
2222
* 2 = leave
2323
*/
24-
var transition = module.exports = function (el, stage, changeState, compiler) {
24+
var transition = module.exports = function (el, stage, cb, compiler) {
25+
26+
var changeState = function () {
27+
cb()
28+
compiler.execHook(stage > 0 ? 'enteredView' : 'leftView')
29+
}
2530

2631
if (compiler.init) {
2732
changeState()
@@ -79,7 +84,6 @@ function applyTransitionClass (el, stage, changeState, compiler) {
7984
classList.add(enterClass)
8085
// append
8186
changeState()
82-
compiler.execHook('enteredView')
8387
// force a layout so transition can be triggered
8488
/* jshint unused: false */
8589
var forceLayout = el.clientHeight
@@ -98,7 +102,6 @@ function applyTransitionClass (el, stage, changeState, compiler) {
98102
// actually remove node here
99103
changeState()
100104
classList.remove(leaveClass)
101-
compiler.execHook('leftView')
102105
}
103106
}
104107
// attach transition end listener
@@ -123,30 +126,20 @@ function applyTransitionFunctions (el, stage, changeState, functionId, compiler)
123126

124127
if (stage > 0) { // enter
125128
if (typeof enter !== 'function') {
126-
doEnter()
129+
changeState()
127130
return codes.JS_SKIP_E
128131
}
129-
enter(el, doEnter)
132+
enter(el, changeState)
130133
return codes.JS_E
131134
} else { // leave
132135
if (typeof leave !== 'function') {
133-
doLeave()
136+
changeState()
134137
return codes.JS_SKIP_L
135138
}
136-
leave(el, doLeave)
139+
leave(el, changeState)
137140
return codes.JS_L
138141
}
139142

140-
function doEnter () {
141-
compiler.execHook('enteredView')
142-
changeState()
143-
}
144-
145-
function doLeave () {
146-
compiler.execHook('leftView')
147-
changeState()
148-
}
149-
150143
}
151144

152145
/**

test/unit/specs/directives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ function mockDirective (dirName, tag, type) {
613613
var dir = Vue.directive(dirName),
614614
ret = {
615615
binding: { compiler: { vm: {} } },
616-
compiler: { vm: {}, options: {} },
616+
compiler: { vm: {}, options: {}, execHook: function () {}},
617617
el: document.createElement(tag || 'div')
618618
}
619619
if (typeof dir === 'function') {

test/unit/specs/transition.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,21 @@ describe('UNIT: Transition', function () {
1111

1212
it('should skip if compiler is in init stage', function () {
1313
var c = mockChange(),
14-
code = transition(null, 1, c.change, { init: true })
14+
compiler = mockCompiler()
15+
compiler.init = true
16+
var code = transition(null, 1, c.change, compiler)
1517
assert.ok(c.called)
1618
assert.strictEqual(code, codes.INIT)
19+
assert.ok(compiler.enteredView)
1720
})
1821

1922
it('should skip if no transition is found on the node', function () {
2023
var c = mockChange(),
21-
code = transition(mockEl(), 1, c.change, {})
24+
compiler = mockCompiler(),
25+
code = transition(mockEl(), 1, c.change, compiler)
2226
assert.ok(c.called)
2327
assert.strictEqual(code, codes.SKIP)
28+
assert.ok(compiler.enteredView)
2429
})
2530

2631
})
@@ -31,9 +36,11 @@ describe('UNIT: Transition', function () {
3136

3237
it('should skip if transition is not available', function () {
3338
var c = mockChange(),
34-
code = transition(mockEl('css'), 1, c.change, {})
39+
compiler = mockCompiler(),
40+
code = transition(mockEl('css'), 1, c.change, compiler)
3541
assert.ok(c.called)
3642
assert.strictEqual(code, codes.CSS_SKIP)
43+
assert.ok(compiler.enteredView)
3744
})
3845

3946
// skip the rest
@@ -130,21 +137,27 @@ describe('UNIT: Transition', function () {
130137

131138
it('should skip if correspinding option is not defined', function () {
132139
var c = mockChange(),
133-
code = transition(mockEl('js'), 1, c.change, mockCompiler())
140+
compiler = mockCompiler(),
141+
code = transition(mockEl('js'), 1, c.change, compiler)
134142
assert.ok(c.called)
135143
assert.strictEqual(code, codes.JS_SKIP)
144+
assert.ok(compiler.enteredView)
136145
})
137146

138147
it('should skip if the option is given but the enter/leave func is not defined', function () {
139148
var c = mockChange(),
140-
code = transition(mockEl('js'), 1, c.change, mockCompiler({}))
149+
compiler = mockCompiler({}),
150+
code = transition(mockEl('js'), 1, c.change, compiler)
141151
assert.ok(c.called)
142152
assert.strictEqual(code, codes.JS_SKIP_E)
153+
assert.ok(compiler.enteredView)
143154

144155
c = mockChange()
145-
code = transition(mockEl('js'), -1, c.change, mockCompiler({}))
156+
compiler = mockCompiler({})
157+
code = transition(mockEl('js'), -1, c.change, compiler)
146158
assert.ok(c.called)
147159
assert.strictEqual(code, codes.JS_SKIP_L)
160+
assert.ok(compiler.leftView)
148161
})
149162

150163
describe('enter', function () {

0 commit comments

Comments
 (0)