File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,15 @@ export abstract class TaskStorable extends TaskBase {
2525 return ( this . constructor as typeof TaskStorable ) . taskTtlDone
2626 }
2727
28- static async _load < T extends TaskStorable > ( this : Constructor < T > , sm : StoreManager ) : Promise < T > {
28+ // Factory method to create an instance with the necessary context
29+ static createInstance < T extends TaskStorable > ( this : Constructor < T > , context ?: Partial < T > ) : T {
2930 const instance = new this ( )
31+ Object . assign ( instance , context )
32+ return instance
33+ }
34+
35+ static async _load < T extends TaskStorable > ( this : Constructor < T > , sm : StoreManager , context ?: Partial < T > ) : Promise < T > {
36+ const instance = ( this as any ) . createInstance ( context )
3037 // get all task keys
3138 const keys = await sm . keys ( `${ instance . getTaskPrefix ( ) } *` , true )
3239 // get the first task (del when finish)
@@ -35,8 +42,8 @@ export abstract class TaskStorable extends TaskBase {
3542 return instance . fromString ( serializedTask )
3643 }
3744
38- static async load < T extends TaskStorable > ( this : Constructor < T > , sm : StoreManager ) : Promise < T > {
39- return await ( this as any ) . _load ( sm )
45+ static async load < T extends TaskStorable > ( this : Constructor < T > , sm : StoreManager , context ?: Partial < T > ) : Promise < T > {
46+ return await ( this as any ) . _load ( sm , context )
4047 }
4148
4249 async save ( sm : StoreManager ) {
You can’t perform that action at this time.
0 commit comments