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

#40 change Wechaty class Singleton

上级 e04cd906
......@@ -44,13 +44,13 @@ class Wechaty extends EventEmitter {
public uuid: string
constructor(private setting: WechatySetting) {
private constructor(private setting: WechatySetting) {
super()
log.verbose('Wechaty', 'contructor()')
if (Wechaty._instance instanceof Wechaty) {
throw new Error('Wechaty must be singleton')
}
// if (Wechaty._instance instanceof Wechaty) {
// throw new Error('Wechaty must be singleton')
// }
setting.type = setting.type || Config.puppet
setting.head = setting.head || Config.head
......@@ -69,10 +69,13 @@ class Wechaty extends EventEmitter {
this.inited = false
Wechaty._instance = this
// Wechaty._instance = this
}
public static instance() {
public static instance(setting: WechatySetting) {
if (!this._instance) {
this._instance = new Wechaty(setting)
}
return this._instance
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册