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

puppet Contact & Room support provide the payload when load()

上级 04c559dd
......@@ -103,8 +103,9 @@ export class Contact extends PuppetAccessory implements Sayable {
* About the Generic: https://stackoverflow.com/q/43003970/1123955
*/
public static load<T extends typeof Contact>(
this : T,
id : string,
this : T,
id : string,
payload? : ContactPayload,
): T['prototype'] {
if (!this.pool) {
log.verbose('Contact', 'load(%s) init pool', id)
......@@ -121,6 +122,9 @@ export class Contact extends PuppetAccessory implements Sayable {
}
const existingContact = this.pool.get(id)
if (existingContact) {
if (payload) {
existingContact.payload = payload
}
return existingContact
}
......@@ -128,6 +132,11 @@ export class Contact extends PuppetAccessory implements Sayable {
// so we force `this as any` at here to make the call.
const newContact = new (this as any)(id)
this.pool.set(id, newContact)
if (payload) {
newContact.payload = payload
}
return newContact
}
......
......@@ -174,8 +174,9 @@ export class Room extends PuppetAccessory implements Sayable {
* About the Generic: https://stackoverflow.com/q/43003970/1123955
*/
public static load<T extends typeof Room>(
this : T,
id : string,
this : T,
id : string,
payload? : RoomPayload,
): T['prototype'] {
if (!this.pool) {
this.pool = new Map<string, Room>()
......@@ -183,10 +184,17 @@ export class Room extends PuppetAccessory implements Sayable {
const existingRoom = this.pool.get(id)
if (existingRoom) {
if (payload) {
existingRoom.payload = payload
}
return existingRoom
}
const newRoom = new (this as any)(id)
if (payload) {
newRoom.payload = payload
}
this.pool.set(id, newRoom)
return newRoom
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册