@@ -14,11 +14,18 @@ class GecutContextDirective<T> extends GecutAsyncDirective {
14
14
15
15
protected _$signal ?: ContextSignal < T > ;
16
16
protected _$render ?: ( data : T ) => unknown ;
17
+ protected _$loading ?: ( ) => unknown ;
17
18
18
- render ( signalContext : ContextSignal < T > , render : ( data : T ) => unknown = ( data ) => String ( data ) ) : unknown {
19
- this . log . methodArgs ?.( 'render' , { signalContext, render} ) ;
19
+ render (
20
+ signalContext : ContextSignal < T > ,
21
+ render : ( data : T ) => unknown = ( data ) => data ,
22
+ loading ?: ( ) => unknown ,
23
+ ) : unknown {
24
+ signalContext ;
25
+ this . log . methodArgs ?.( 'render' , { signalContext} ) ;
20
26
21
27
this . _$render = render ;
28
+ this . _$loading = loading ;
22
29
if ( this . _$signal !== signalContext ) {
23
30
// When the observable changes, unsubscribe to the old one and subscribe to the new one
24
31
this . unsubscribe ?.( ) ;
@@ -35,6 +42,10 @@ class GecutContextDirective<T> extends GecutAsyncDirective {
35
42
subscribe ( signalContext : ContextSignal < T > ) : void {
36
43
this . log . method ?.( 'subscribe' ) ;
37
44
45
+ if ( this . _$loading ) {
46
+ this . setValue ( this . _$loading ( ) ) ;
47
+ }
48
+
38
49
this . unsubscribe = signalContext . subscribe (
39
50
( v ) => {
40
51
this . setValue ( this . _$render ! ( v ) ) ;
@@ -46,7 +57,7 @@ class GecutContextDirective<T> extends GecutAsyncDirective {
46
57
// When the directive is disconnected from the DOM, unsubscribe to ensure
47
58
// the directive instance can be garbage collected
48
59
override disconnected ( ) : void {
49
- this . unsubscribe ! ( ) ;
60
+ this . unsubscribe ?. ( ) ;
50
61
}
51
62
// If the subtree the directive is in was disconnected and subsequently
52
63
// re-connected, re-subscribe to make the directive operable again
0 commit comments