Skip to content

Commit

Permalink
fix enteredView/leftView
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 19, 2013
1 parent 9ec0259 commit f9bebc7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
27 changes: 10 additions & 17 deletions src/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ var endEvent = sniffTransitionEndEvent(),
* 1 = enter
* 2 = leave
*/
var transition = module.exports = function (el, stage, changeState, compiler) {
var transition = module.exports = function (el, stage, cb, compiler) {

var changeState = function () {
cb()
compiler.execHook(stage > 0 ? 'enteredView' : 'leftView')
}

if (compiler.init) {
changeState()
Expand Down Expand Up @@ -79,7 +84,6 @@ function applyTransitionClass (el, stage, changeState, compiler) {
classList.add(enterClass)
// append
changeState()
compiler.execHook('enteredView')
// force a layout so transition can be triggered
/* jshint unused: false */
var forceLayout = el.clientHeight
Expand All @@ -98,7 +102,6 @@ function applyTransitionClass (el, stage, changeState, compiler) {
// actually remove node here
changeState()
classList.remove(leaveClass)
compiler.execHook('leftView')
}
}
// attach transition end listener
Expand All @@ -123,30 +126,20 @@ function applyTransitionFunctions (el, stage, changeState, functionId, compiler)

if (stage > 0) { // enter
if (typeof enter !== 'function') {
doEnter()
changeState()
return codes.JS_SKIP_E
}
enter(el, doEnter)
enter(el, changeState)
return codes.JS_E
} else { // leave
if (typeof leave !== 'function') {
doLeave()
changeState()
return codes.JS_SKIP_L
}
leave(el, doLeave)
leave(el, changeState)
return codes.JS_L
}

function doEnter () {
compiler.execHook('enteredView')
changeState()
}

function doLeave () {
compiler.execHook('leftView')
changeState()
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/specs/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ function mockDirective (dirName, tag, type) {
var dir = Vue.directive(dirName),
ret = {
binding: { compiler: { vm: {} } },
compiler: { vm: {}, options: {} },
compiler: { vm: {}, options: {}, execHook: function () {}},
el: document.createElement(tag || 'div')
}
if (typeof dir === 'function') {
Expand Down
25 changes: 19 additions & 6 deletions test/unit/specs/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ describe('UNIT: Transition', function () {

it('should skip if compiler is in init stage', function () {
var c = mockChange(),
code = transition(null, 1, c.change, { init: true })
compiler = mockCompiler()
compiler.init = true
var code = transition(null, 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.INIT)
assert.ok(compiler.enteredView)
})

it('should skip if no transition is found on the node', function () {
var c = mockChange(),
code = transition(mockEl(), 1, c.change, {})
compiler = mockCompiler(),
code = transition(mockEl(), 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.SKIP)
assert.ok(compiler.enteredView)
})

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

it('should skip if transition is not available', function () {
var c = mockChange(),
code = transition(mockEl('css'), 1, c.change, {})
compiler = mockCompiler(),
code = transition(mockEl('css'), 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.CSS_SKIP)
assert.ok(compiler.enteredView)
})

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

it('should skip if correspinding option is not defined', function () {
var c = mockChange(),
code = transition(mockEl('js'), 1, c.change, mockCompiler())
compiler = mockCompiler(),
code = transition(mockEl('js'), 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.JS_SKIP)
assert.ok(compiler.enteredView)
})

it('should skip if the option is given but the enter/leave func is not defined', function () {
var c = mockChange(),
code = transition(mockEl('js'), 1, c.change, mockCompiler({}))
compiler = mockCompiler({}),
code = transition(mockEl('js'), 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.JS_SKIP_E)
assert.ok(compiler.enteredView)

c = mockChange()
code = transition(mockEl('js'), -1, c.change, mockCompiler({}))
compiler = mockCompiler({})
code = transition(mockEl('js'), -1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.JS_SKIP_L)
assert.ok(compiler.leftView)
})

describe('enter', function () {
Expand Down

0 comments on commit f9bebc7

Please sign in to comment.