From 1818c03863815ef2e46f10692ac553c324319a97 Mon Sep 17 00:00:00 2001 From: "Zhuohuan LI (CARPE DIEM)" Date: Tue, 18 Oct 2016 00:58:19 +0800 Subject: [PATCH] test pre-commit hook --- src/state-monitor.spec.ts | 11 +++++++++++ src/state-monitor.ts | 15 +++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/state-monitor.spec.ts b/src/state-monitor.spec.ts index 891c4d00..e342853f 100644 --- a/src/state-monitor.spec.ts +++ b/src/state-monitor.spec.ts @@ -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') +}) diff --git a/src/state-monitor.ts b/src/state-monitor.ts index 1ae94eb8..51191c58 100644 --- a/src/state-monitor.ts +++ b/src/state-monitor.ts @@ -26,8 +26,7 @@ export class StateMonitor { 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 { 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 } } -- GitLab