@@ -34,27 +34,28 @@ export class FnContextKey<Args extends any[], Ret = void>
34
34
implements FnContextRef < Args , Ret , AfterEvent < ( ( this : void , ...args : Args ) => Ret ) [ ] > > {
35
35
36
36
/**
37
- * A function that will be called unless the function or fallback provided.
37
+ * Constructs a function that will be called unless fallback provided.
38
38
*/
39
- readonly byDefault : ( this : void , ...args : Args ) => Ret ;
39
+ readonly byDefault : ( this : void , context : ContextValues ) => ( this : void , ...args : Args ) => Ret ;
40
40
41
41
/**
42
42
* Constructs updatable context function key.
43
43
*
44
44
* @param name Human-readable key name.
45
45
* @param seedKey Value seed key. A new one will be constructed when omitted.
46
- * @param byDefault The default function to call. If unspecified then the default function would raise an error.
46
+ * @param byDefault Constructs a default function to call. If unspecified then the default function would raise
47
+ * an error.
47
48
*/
48
49
constructor (
49
50
name : string ,
50
51
{
51
52
seedKey,
52
- byDefault = ( ) => { throw new ContextKeyError ( this ) ; } ,
53
+ byDefault = ( ) => ( ) => { throw new ContextKeyError ( this ) ; } ,
53
54
} : {
54
55
seedKey ?: ContextSeedKey <
55
56
( ( this : void , ...args : Args ) => Ret ) | EventKeeper < ( ( this : void , ...args : Args ) => Ret ) [ ] > ,
56
57
AfterEvent < ( ( this : void , ...args : Args ) => Ret ) [ ] > > ,
57
- byDefault ?: ( this : void , ...args : Args ) => Ret ,
58
+ byDefault ?: ( this : void , context : ContextValues ) => ( this : void , ...args : Args ) => Ret ,
58
59
} = { } ,
59
60
) {
60
61
super ( name , seedKey ) ;
@@ -76,9 +77,9 @@ export class FnContextKey<Args extends any[], Ret = void>
76
77
delegated = fns [ fns . length - 1 ] ;
77
78
} else {
78
79
79
- const fallback = opts . byDefault ( ( ) => this . byDefault ) ;
80
+ const fallback = opts . byDefault ( ( ) => this . byDefault ( opts . context ) ) ;
80
81
81
- delegated = fallback || this . byDefault ;
82
+ delegated = fallback || this . byDefault ( opts . context ) ;
82
83
}
83
84
} ) ;
84
85
0 commit comments