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 {
25
25
return ( this . constructor as typeof TaskStorable ) . taskTtlDone
26
26
}
27
27
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 {
29
30
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 )
30
37
// get all task keys
31
38
const keys = await sm . keys ( `${ instance . getTaskPrefix ( ) } *` , true )
32
39
// get the first task (del when finish)
@@ -35,8 +42,8 @@ export abstract class TaskStorable extends TaskBase {
35
42
return instance . fromString ( serializedTask )
36
43
}
37
44
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 )
40
47
}
41
48
42
49
async save ( sm : StoreManager ) {
You can’t perform that action at this time.
0 commit comments