You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This javascript library provides utility functions for handling observables, signals, and asynchronous data streams across various reactive programming libraries. It supports flexible customization to integrate with different libraries, ensuring seamless subscription management and automatic cleanup.
10
10
11
11
## Table of Contents
12
12
13
-
-[Installation](#installation)
14
-
-[Lite](#lite)
15
-
-[Usage](#usage)
16
-
-[Basic Setup](#basic-setup)
17
-
-[Promise](#promise)
18
-
-[Subscribing to Observables](#subscribing-to-observables)
19
-
-[API Overview](#api-overview)
20
-
-[Checking if an Object is Observable](#checking-if-an-object-is-observable)
21
-
-[Customizing for Your Reactive Library](#customizing-for-your-reactive-library)
22
-
-[Examples](#examples)
23
-
-[Any Source](#any-source)
24
-
-[Solid.js](#solidjs)
25
-
-[Preact Signals](#preact-signals)
26
-
-[usignal](#usignal)
27
-
-[@webreflection/signal](#webreflectionsignal)
28
-
-[ulive](#ulive)
29
-
-[RxJS Subject](#rxjs-subject)
30
-
-[Async Iterable](#async-iterable)
31
-
-[Synchronous Iterable](#synchronous-iterable)
32
-
-[Finalization and Cleanup](#finalization-and-cleanup)
33
-
-[License](#license)
34
-
-[Thanks](#thanks)
13
+
-[Installation](#installation)
14
+
-[Lite](#lite)
15
+
-[Usage](#usage)
16
+
-[Basic Setup](#basic-setup)
17
+
-[Promise](#promise)
18
+
-[Subscribing to Observables](#subscribing-to-observables)
19
+
-[API Overview](#api-overview)
20
+
-[Checking if an Object is Observable](#checking-if-an-object-is-observable)
21
+
-[Customizing for Your Reactive Library](#customizing-for-your-reactive-library)
22
+
-[Examples](#examples)
23
+
-[Any Source](#any-source)
24
+
-[Solid.js](#solidjs)
25
+
-[Preact Signals](#preact-signals)
26
+
-[usignal](#usignal)
27
+
-[@webreflection/signal](#webreflectionsignal)
28
+
-[ulive](#ulive)
29
+
-[RxJS Subject](#rxjs-subject)
30
+
-[Async Iterable](#async-iterable)
31
+
-[Finalization and Cleanup](#finalization-and-cleanup)
32
+
-[License](#license)
33
+
-[Thanks](#thanks)
35
34
36
35
## Installation
37
36
@@ -43,8 +42,6 @@ This javascript library provides utility functions for handling observables, sig
43
42
44
43
**es**: https://unpkg.com/usub?module
45
44
46
-
## Installation
47
-
48
45
To use this utility, simply import it into your project:
49
46
50
47
```js
@@ -53,13 +50,13 @@ import { is, api, sub, get } from "usub";
53
50
54
51
### lite
55
52
56
-
The lite utility does not contain subscribe, and set method for observ-* patterns.
53
+
The lite utility does not contain subscribe, and set method for observ-\* patterns.
57
54
58
55
**cdn**: https://unpkg.com/usub/lite
59
56
60
57
**es**: https://unpkg.com/usub/lite?module
61
58
62
-
## Installation
59
+
## Lite Installation
63
60
64
61
To use lite version, simply import it into your project:
65
62
@@ -73,10 +70,10 @@ import { is, api, sub, get } from "usub/lite";
73
70
74
71
The library exports four primary functions:
75
72
76
-
-**`is`**: Checks if a value is considered an observable or reactive signal.
77
-
-**`api`**: Provides utility functions that can be customized to work with different reactive libraries.
78
-
-**`sub`**: Subscribes to an observable or other async/reactive patterns.
79
-
-**`get`**: get function to retrieve reactive data
73
+
-**`is`**: Checks if a value is considered an observable or reactive signal.
74
+
-**`api`**: Provides utility functions that can be customized to work with different reactive libraries.
75
+
-**`sub`**: Subscribes to an observable or other async/reactive patterns.
76
+
-**`get`**: get function to retrieve reactive data
80
77
81
78
### Subscribing to Observables
82
79
@@ -136,7 +133,7 @@ The library is designed to be easily customized for different reactive programmi
136
133
137
134
### API Overview
138
135
139
-
-**api.any(target)(next, err, complete)**
136
+
-**api.any(target)(next, err, complete)**
140
137
141
138
api.any is a placeholder within the api object that can be used to represent or handle any observable-like object.
142
139
@@ -152,19 +149,19 @@ By default, api.any is set to undefined. This means that if it is not explicitly
152
149
153
150
You can customize api.any to handle your specific observable implementations. For example, you might set api.any to a function that processes different observable types or provides default behavior for handling observable subscriptions and notifications.
154
151
155
-
-**api.effect(f)**
152
+
-**api.effect(f)**
156
153
157
154
Sets up the effect execution method. This function is where you define how to apply effects in your reactive library (e.g., createEffect in Solid.js, effect in Preact Signals).
158
155
159
-
-**api.is(v)**
156
+
-**api.is(v)**
160
157
161
158
Defines how to check if a value is a signal or observable. This is where you identify reactive signals from your library (e.g., checking if a value is an instance of Signal).
162
159
163
-
-**api.get(v)**
160
+
-**api.get(v)**
164
161
165
162
Specifies how to retrieve the current value from a signal or observable. This function is where you define how to extract the current value from your reactive signal (e.g., v?.value or v?.()).
166
163
167
-
-**api.cleanup()**
164
+
-**api.cleanup()**
168
165
169
166
Provides a function to handle cleanup logic. This can be used to define any custom cleanup behavior required when a subscription is no longer needed.
The library uses FinalizationRegistry to automatically clean up subscriptions when objects are garbage collected. This helps prevent memory leaks by ensuring that subscriptions are properly terminated when no longer needed.
@@ -373,4 +342,4 @@ This library is provided "as-is" under the MIT license. Feel free to use, modify
0 commit comments