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

Typescript transition step 7: fix puppet.ts & tslint

上级 5787f6da
......@@ -10,11 +10,19 @@
*
*/
const EventEmitter = require('events')
import { EventEmitter } from 'events'
import log from './brolog-env'
import Contact from './contact'
import Message from './message'
import Room from './room'
import log from './brolog-env'
class Puppet extends EventEmitter {
private _user: Contact
private _targetState: string
private _currentState: string
constructor() {
super()
......@@ -30,7 +38,7 @@ class Puppet extends EventEmitter {
}
// targetState : 'live' | 'dead'
targetState(newState) {
public targetState(newState) {
if (newState) {
log.verbose('Puppet', 'targetState(%s)', newState)
this._targetState = newState
......@@ -39,7 +47,7 @@ class Puppet extends EventEmitter {
}
// currentState : 'birthing' | 'killing'
currentState(newState) {
public currentState(newState) {
if (newState) {
log.verbose('Puppet', 'currentState(%s)', newState)
this._currentState = newState
......@@ -47,14 +55,16 @@ class Puppet extends EventEmitter {
return this._currentState
}
// @deprecated
// readyState(newState) {
// if (newState) {
// log.verbose('Puppet', 'readyState() set to "%s"', newState)
// this._readyState = newState
// }
// return this._readyState
// }
public self(message?: Message): boolean | Contact {
throw new Error('pure virtual interface function')
}
public user(contact?: Contact) {
if (contact) {
this._user = contact
}
return this._user
}
/**
* let puppet send message
......@@ -62,14 +72,15 @@ class Puppet extends EventEmitter {
* @param <Message> message - the message to be sent
* @return <Promise>
*/
send(message) { throw new Error('To Be Implemented') }
reply(message, reply) { throw new Error('To Be Implemented') }
public send(message): Promise<any> { throw new Error('To Be Implemented') }
public reply(message, reply): Promise<any> { throw new Error('To Be Implemented') }
logout() { throw new Error('To Be Implementsd') }
quit() { throw new Error('To Be Implementsd') }
ding() { throw new Error('To Be Implementsd') }
public reset(reason?: string) { throw new Error('To Be Implementsd') }
public logout(): Promise<any> { throw new Error('To Be Implementsd') }
public quit(): Promise<any> { throw new Error('To Be Implementsd') }
public ding(data?: string): Promise<any> { throw new Error('To Be Implementsd') }
getContact(id) { // for unit testing
public getContact(id): Promise<any> { // for unit testing
log.verbose('Puppet', `Interface method getContact(${id})`)
throw new Error('Absolute Interface Method should never to be called')
// return Promise.resolve({UserName: 'WeChaty', NickName: 'Puppet'})
......@@ -78,11 +89,17 @@ class Puppet extends EventEmitter {
// () { throw new Error('To Be Implemented') }
}
Object.assign(Puppet, {
Message: require('./message')
, Contact: require('./contact')
, Room: require('./room')
})
// Object.assign(Puppet, {
// Message: require('./message')
// , Contact: require('./contact')
// , Room: require('./room')
// })
// module.exports = Puppet
export default Puppet
export {
Contact
, Message
, Puppet
, Room
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册