enteredView/leftView -> attached/detached

This commit is contained in:
Evan You 2014-02-13 18:00:12 -05:00
parent 11e1a25f5b
commit 7a4de5f2d3
4 changed files with 22 additions and 22 deletions

View File

@ -20,7 +20,7 @@ var Emitter = require('./emitter'),
hooks = [
'created', 'ready',
'beforeDestroy', 'afterDestroy',
'enteredView', 'leftView'
'attached', 'detached'
]
/**

View File

@ -23,7 +23,7 @@ var transition = module.exports = function (el, stage, cb, compiler) {
var changeState = function () {
cb()
compiler.execHook(stage > 0 ? 'enteredView' : 'leftView')
compiler.execHook(stage > 0 ? 'attached' : 'detached')
}
if (compiler.init) {

View File

@ -788,17 +788,17 @@ describe('UNIT: API', function () {
})
describe('enteredView', function () {
describe('attached', function () {
it('should be called after enter view', function () {
var called1 = false, called2 = false,
test = new Vue({
enteredView: function () {
attached: function () {
assert.strictEqual(this.$el.parentNode, document.getElementById('test'))
called1 = true
}
})
test.$on('hook:enteredView', function () {
test.$on('hook:attached', function () {
called2 = true
})
test.$appendTo('#test')
@ -808,17 +808,17 @@ describe('UNIT: API', function () {
})
describe('leftView', function () {
describe('detached', function () {
it('should be called after left view', function () {
var called1 = false, called2 = false,
test = new Vue({
leftView: function () {
detached: function () {
assert.strictEqual(this.$el.parentNode, null)
called1 = true
}
})
test.$on('hook:leftView', function () {
test.$on('hook:detached', function () {
called2 = true
})
document.getElementById('test').appendChild(test.$el)

View File

@ -16,7 +16,7 @@ describe('UNIT: Transition', function () {
var code = transition(null, 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.INIT)
assert.ok(compiler.enteredView)
assert.ok(compiler.attached)
})
it('should skip if no transition is found on the node', function () {
@ -25,7 +25,7 @@ describe('UNIT: Transition', function () {
code = transition(mockEl(), 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.SKIP)
assert.ok(compiler.enteredView)
assert.ok(compiler.attached)
})
})
@ -40,7 +40,7 @@ describe('UNIT: Transition', function () {
code = transition(mockEl('css'), 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.CSS_SKIP)
assert.ok(compiler.enteredView)
assert.ok(compiler.attached)
})
// skip the rest
@ -83,8 +83,8 @@ describe('UNIT: Transition', function () {
assert.strictEqual(code, codes.CSS_E)
})
it('should have called enteredView hook', function () {
assert.ok(compiler.enteredView)
it('should have called attached hook', function () {
assert.ok(compiler.attached)
})
})
@ -125,8 +125,8 @@ describe('UNIT: Transition', function () {
assert.strictEqual(code, codes.CSS_L)
})
it('should have called leftView hook', function () {
assert.ok(compiler.leftView)
it('should have called detached hook', function () {
assert.ok(compiler.detached)
})
})
@ -141,7 +141,7 @@ describe('UNIT: Transition', function () {
code = transition(mockEl('js'), 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.JS_SKIP)
assert.ok(compiler.enteredView)
assert.ok(compiler.attached)
})
it('should skip if the option is given but the enter/leave func is not defined', function () {
@ -150,14 +150,14 @@ describe('UNIT: Transition', function () {
code = transition(mockEl('js'), 1, c.change, compiler)
assert.ok(c.called)
assert.strictEqual(code, codes.JS_SKIP_E)
assert.ok(compiler.enteredView)
assert.ok(compiler.attached)
c = mockChange()
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)
assert.ok(compiler.detached)
})
describe('enter', function () {
@ -182,8 +182,8 @@ describe('UNIT: Transition', function () {
assert.strictEqual(code, codes.JS_E)
})
it('should have called enteredView hook', function () {
assert.ok(compiler.enteredView)
it('should have called attached hook', function () {
assert.ok(compiler.attached)
})
})
@ -210,8 +210,8 @@ describe('UNIT: Transition', function () {
assert.strictEqual(code, codes.JS_L)
})
it('should have called leftView hook', function () {
assert.ok(compiler.leftView)
it('should have called detached hook', function () {
assert.ok(compiler.detached)
})
})