1
1
const
2
2
// FinalizationRegistry to clean up subscriptions when objects are garbage collected
3
- registry = new FinalizationRegistry ( unsub => ( unsub && unsub ?. call ?. ( ) ) ) ,
3
+ registry = new FinalizationRegistry ( unsub => unsub ?. call ( ) ) ,
4
4
5
5
// API object providing basic functions for handling effects and values
6
6
api = {
7
7
// Handle any reactive subscription
8
- any : undefined ,
9
- // If any cleanup is requested
10
- cleanup : undefined ,
8
+ // any: undefined,
9
+ // // If any cleanup is requested
10
+ // cleanup: undefined,
11
11
// Executes the provided function
12
- effect : ( f ) => f ( ) ,
12
+ effect : f => f ( ) ,
13
13
// Returns false for any value (placeholder implementation)
14
- is : ( v ) => v ?. call ,
14
+ is : v => v ?. call ,
15
15
// Retrieves the value (returns it as is)
16
- get : ( v ) => v ?. call ( ) ,
16
+ get : v => v ?. call ( ) ,
17
17
} ,
18
18
19
19
// Utility function to handle and unwrap values of signals, observable, etc especially functions
@@ -26,10 +26,10 @@ const
26
26
api . is ( arg ) || // Custom observable check
27
27
arg . call // Function
28
28
) ,
29
-
29
+
30
30
// Subscribe to an observable or value, and provide a callback for each value
31
31
sub = ( target , stop , unsub ) => ( next , error , cleanup ) => target && (
32
- unsub = ( ( ! api ? .any && ( api . is ( target ) || target ? .call ) ) && api . effect ( ( ) => ( next ( get ( target ) ) , api ? .cleanup ?. ( cleanup ) , cleanup ) ) ) ||
32
+ unsub = ( ( ! api . any && ( api . is ( target ) || target . call ) ) && api . effect ( ( ) => ( next ( get ( target ) ) , api . cleanup ?. ( cleanup ) , cleanup ) ) ) ||
33
33
(
34
34
target . then ?. ( v => ( ! stop && next ( get ( v ) ) , cleanup ?. ( ) ) , error ) ||
35
35
target [ Symbol . asyncIterator ] && ( async v => {
40
40
} catch ( err ) { error ?. ( err ) }
41
41
} ) ( )
42
42
) && ( _ => stop = 1 ) ||
43
- ( api ? .any ?. ( target ) ?. ( next , error , cleanup ) ) ,
43
+ ( api . any ?. ( target ) ?. ( next , error , cleanup ) ) ,
44
44
// register autocleanup
45
45
registry . register ( target , unsub ) ,
46
46
unsub
0 commit comments