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

prevent to set the global Contact.pool

上级 c228287a
......@@ -70,6 +70,8 @@ export interface ContactPayload {
weixin?: string,
}
export const POOL = Symbol('pool')
/**
* All wechat contacts(friend) will be encapsulated as a Contact.
*
......@@ -82,7 +84,19 @@ export class Contact extends PuppetAccessory implements Sayable {
public static Type = ContactType
public static Gender = Gender
protected static pool: Map<string, Contact>
protected static [POOL]: Map<string, Contact>
protected static get pool() {
return this[POOL]
}
protected static set pool(newPool: Map<string, Contact>) {
if (this === Contact) {
throw new Error(
'The global Contact class can not be used directly!'
+ 'See: https://github.com/Chatie/wechaty/issues/1217',
)
}
this[POOL] = newPool
}
/**
* @private
......@@ -96,6 +110,12 @@ export class Contact extends PuppetAccessory implements Sayable {
log.verbose('Contact', 'load(%s) init pool', id)
this.pool = new Map<string, Contact>()
}
if (this === Contact) {
throw new Error(
'The lgobal Contact class can not be used directly!'
+ 'See: https://github.com/Chatie/wechaty/issues/1217',
)
}
if (this.pool === Contact.pool) {
throw new Error('the current pool is equal to the global pool error!')
}
......@@ -194,7 +214,9 @@ export class Contact extends PuppetAccessory implements Sayable {
}
/**
*
* Instance properties
*
*/
protected payload?: ContactPayload
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册