提交 1818c038 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

test pre-commit hook

上级 523ca27f
......@@ -43,3 +43,14 @@ test('StateMonitor smoking test', t => {
t.is(sm.current(), 'A', 'current should be A')
t.false(sm.stable(), 'should not be stable')
})
test('StateMonitor stable', t => {
const sm = new StateMonitor<'A', 'B'>('SmokingTest', 'A')
sm.current('B')
t.true(sm.stable(), 'should be stable')
sm.current('B', false)
t.false(sm.stable(), 'should not be stable')
sm.current('B', true)
t.true(sm.stable(), 'should be stable')
})
......@@ -26,8 +26,7 @@ export class StateMonitor <A, B>{
log.verbose('StateMonitor', 'constructor(%s, %s)', client, initState)
this.target(initState)
this.current(initState)
this.stable(true)
this.current(initState, true)
}
public target(newState?: A|B): A|B {
......@@ -59,16 +58,8 @@ export class StateMonitor <A, B>{
return this._current
}
public stable(stable?: boolean) {
if (typeof stable === 'boolean') {
log.verbose('StateMonitor', 'stable(%s) %s state change from %s to %s'
, stable
, this.client
, this._stable, stable)
this._stable = stable
} else {
log.verbose('StateMonitor', 'stable() %s state is %s', this.client, this._stable)
}
public stable() {
log.verbose('StateMonitor', 'stable() %s state is %s', this.client, this._stable)
return this._stable
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册