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

fix win32 sloc bug, code clean

上级 dd228d20
......@@ -23,7 +23,7 @@
"eslint": "eslint \"{bin,example,src,test}/**/*.js\"",
"tslint": "tslint \"{bin,example,src,test}/**/*.ts\" && tsc --noEmit",
"pretest": "npm run lint && npm run clean && npm run build",
"sloc": "sloc . --details --format cli-table --keys total,source,comment --exclude \"\\.\\./|dist/|doc/|node_modules/\" && sloc ./ --exclude \"\\.\\./|dist/|doc/|node_modules/\"",
"sloc": "sloc . --details --format cli-table --keys total,source,comment --exclude \"\\.\\.[\\/]|dist[\\/]|doc[\\/]|node_modules[\\/]\" && sloc ./ --exclude \"\\.\\.[\\/]|dist[\\/]|doc[\\/]|node_modules[\\/]\"",
"test": "npm run test:chrome",
"posttest": "npm run clean && npm run sloc",
"test:phantomjs": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=phantomjs ava --timeout=10m \"dist/test/*.spec.js\"",
......
......@@ -49,8 +49,8 @@ export class IoClient {
// this.targetState('disconnected')
// this.currentState('disconnected')
this.state.target('offline')
this.state.current('offline')
// this.state.target('offline')
// this.state.current('offline')
}
// // targetState : 'connected' | 'disconnected'
......
......@@ -80,8 +80,8 @@ export class Io {
// this.purpose('offline')
// this.targetState('disconnected')
// this.currentState('disconnected')
this.state.target('offline')
this.state.current('offline')
// this.state.target('offline')
// this.state.current('offline')
}
// // targetState : 'connected' | 'disconnected'
......
......@@ -46,8 +46,8 @@ export class Browser extends EventEmitter {
// this.targetState('close')
// this.currentState('close')
this.state.target('close')
this.state.current('close')
// this.state.target('close')
// this.state.current('close')
this.driver = new BrowserDriver(this.setting.head)
this.cookie = new BrowserCookie(this.driver, this.setting.sessionFile)
......
......@@ -47,8 +47,8 @@ export abstract class Puppet extends EventEmitter implements Sayable {
// this.targetState('dead')
// this.currentState('dead')
this.state.target('dead')
this.state.current('dead')
// this.state.target('dead')
// this.state.current('dead')
}
// targetState : 'live' | 'dead'
......
......@@ -15,8 +15,11 @@ import test from 'ava'
import StateMonitor from './state-monitor'
test('StateMonitor smoking test', t => {
const CLIENT_NAME = 'StateMonitorTest'
const sm = new StateMonitor<'A', 'B'>(CLIENT_NAME, 'A')
t.is(sm.client(), CLIENT_NAME, 'should get the same client name as init')
const sm = new StateMonitor<'A', 'B'>('SmokingTest', 'A')
t.is(sm.current(), 'A', 'current should be A')
t.is(sm.target(), 'A', 'target should be A')
t.true(sm.stable(), 'should be stable')
......@@ -45,7 +48,7 @@ test('StateMonitor smoking test', t => {
})
test('StateMonitor stable', t => {
const sm = new StateMonitor<'A', 'B'>('SmokingTest', 'A')
const sm = new StateMonitor<'A', 'B'>('StateMonitorTest', 'A')
sm.current('B')
t.true(sm.stable(), 'should be stable')
......
......@@ -21,8 +21,8 @@ export class StateMonitor <A, B>{
private _current: A|B
private _stable: boolean
constructor(private client: string, initState: A|B) {
log.verbose('StateMonitor', 'constructor(%s, %s)', client, initState)
constructor(private _client: string, initState: A|B) {
log.verbose('StateMonitor', 'constructor(%s, %s)', _client, initState)
this._target = initState
this._current = initState
......@@ -35,13 +35,13 @@ export class StateMonitor <A, B>{
public target(newState?: A|B): A|B {
if (newState) {
log.verbose('StateMonitor', '%s.state.target(%s) from %s'
, this.client
, this._client
, newState
, this._target
)
this._target = newState
} else {
log.silly('StateMonitor', '%s.state.target() is %s', this.client, this._target)
log.silly('StateMonitor', '%s.state.target() is %s', this._client, this._target)
}
return this._target
}
......@@ -53,7 +53,7 @@ export class StateMonitor <A, B>{
public current(newState?: A|B, stable = true): A|B {
if (newState) {
log.verbose('StateMonitor', '%s.state.current(%s, %s) from (%s, %s)'
, this.client
, this._client
, newState, stable
, this._current, this._stable
)
......@@ -61,7 +61,7 @@ export class StateMonitor <A, B>{
&& stable === false // warn for inprocess current state change twice, mostly like a logic bug outside
) {
log.warn('StateMonitor', '%s.state.current(%s, %s) called but there are already in the same state'
, this.client
, this._client
, newState, stable
)
const e = new Error('current unchange')
......@@ -70,7 +70,7 @@ export class StateMonitor <A, B>{
this._current = newState
this._stable = stable
} else {
log.silly('StateMonitor', '%s.state.current() is %s', this.client, this._current)
log.silly('StateMonitor', '%s.state.current() is %s', this._client, this._current)
}
return this._current
}
......@@ -79,7 +79,7 @@ export class StateMonitor <A, B>{
* does the current state be stable(not inprocess)?
*/
public stable() {
log.silly('StateMonitor', '%s.state.stable() is %s', this.client, this._stable)
log.silly('StateMonitor', '%s.state.stable() is %s', this._client, this._stable)
return this._stable
}
......@@ -87,9 +87,16 @@ export class StateMonitor <A, B>{
* does the current state be inprocess(not stable)?
*/
public inprocess() {
log.silly('StateMonitor', '%s.state.inprocess() is %s', this.client, !this._stable)
log.silly('StateMonitor', '%s.state.inprocess() is %s', this._client, !this._stable)
return !this._stable
}
/**
* get the client name
*/
public client() {
return this._client
}
}
export default StateMonitor
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册