reactjs-signal 2.0.3 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/index.d.ts +7 -13
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -207,6 +207,21 @@ useHydrateSignal(countSignal, 10);
|
|
|
207
207
|
|
|
208
208
|
- `EffectScope`: The created effect scope.
|
|
209
209
|
|
|
210
|
+
### `getSignal`
|
|
211
|
+
|
|
212
|
+
Gets the current value of an Alien Signal without subscribing to updates.
|
|
213
|
+
|
|
214
|
+
- Use case: reading signal value outside React components.
|
|
215
|
+
|
|
216
|
+
#### Example
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const countSignal = createSignal(0);
|
|
220
|
+
const { value, setValue } = getSignal(countSignal);
|
|
221
|
+
console.log(value()); // current value
|
|
222
|
+
setValue(10); // set value to 10
|
|
223
|
+
```
|
|
224
|
+
|
|
210
225
|
|
|
211
226
|
## Refer
|
|
212
227
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { signal, computed, effect } from 'alien-signals';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
*
|
|
3
5
|
* React Alien Signals is a **TypeScript** library that provides hooks built on top of [Alien Signals](https://github.com/stackblitz/alien-signals).
|
|
@@ -5,6 +7,7 @@
|
|
|
5
7
|
*
|
|
6
8
|
* @module reactjs-signal
|
|
7
9
|
*/
|
|
10
|
+
|
|
8
11
|
type TWritableSignal<T> = {
|
|
9
12
|
(): T;
|
|
10
13
|
(value: T): void;
|
|
@@ -22,16 +25,7 @@ type TWritableSignal<T> = {
|
|
|
22
25
|
* @param {T} initialValue - The initial value of the signal.
|
|
23
26
|
* @returns {TWritableSignal<T>} The created Alien Signal.
|
|
24
27
|
*/
|
|
25
|
-
declare
|
|
26
|
-
/**
|
|
27
|
-
* Creates a writable Alien Signal that persists its value in localStorage.
|
|
28
|
-
*
|
|
29
|
-
* @template T - The type of the signal value.
|
|
30
|
-
* @param {string} key - The localStorage key to use for persistence.
|
|
31
|
-
* @param {T} initialValue - The initial value of the signal.
|
|
32
|
-
* @returns {TWritableSignal<T>} The created Alien Signal.
|
|
33
|
-
*/
|
|
34
|
-
declare function createSignalStorage<T>(key: string, initialValue: T): TWritableSignal<T>;
|
|
28
|
+
declare const createSignal: typeof signal;
|
|
35
29
|
/**
|
|
36
30
|
* Creates a computed Alien Signal based on a getter function.
|
|
37
31
|
*
|
|
@@ -45,7 +39,7 @@ declare function createSignalStorage<T>(key: string, initialValue: T): TWritable
|
|
|
45
39
|
* @param {() => T} fn - A getter function returning a computed value.
|
|
46
40
|
* @returns {ISignal<T>} The created computed signal.
|
|
47
41
|
*/
|
|
48
|
-
declare
|
|
42
|
+
declare const createComputed: typeof computed;
|
|
49
43
|
/**
|
|
50
44
|
* Creates a side effect in Alien Signals.
|
|
51
45
|
*
|
|
@@ -61,7 +55,7 @@ declare function createComputed<T>(fn: () => T): () => T;
|
|
|
61
55
|
* @param {() => T} fn - A function that will run whenever its tracked signals update.
|
|
62
56
|
* @returns {Effect<T>} The created effect object.
|
|
63
57
|
*/
|
|
64
|
-
declare
|
|
58
|
+
declare const createEffect: typeof effect;
|
|
65
59
|
/**
|
|
66
60
|
* React hook returning `[value, setValue]` for a given Alien Signal.
|
|
67
61
|
* Uses useSyncExternalStore for concurrency-safe re-renders.
|
|
@@ -169,4 +163,4 @@ declare function getSignal<T>(alienSignal: TWritableSignal<T>): {
|
|
|
169
163
|
setValue: (val: T | ((oldVal: T) => T)) => void;
|
|
170
164
|
};
|
|
171
165
|
|
|
172
|
-
export { type TWritableSignal, createComputed, createEffect, createSignal,
|
|
166
|
+
export { type TWritableSignal, createComputed, createEffect, createSignal, getSignal, useHydrateSignal, useSetSignal, useSignal, useSignalEffect, useSignalValue };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {useSyncExternalStore,useEffect}from'react';import {
|
|
1
|
+
import {useSyncExternalStore,useCallback,useEffect}from'react';import {computed,effect,signal}from'alien-signals';var u=new WeakMap;function l(t){let e=u.get(t);return e||(e=new WeakSet,u.set(t,e)),e}var y=signal,W=computed,x=effect;function V(t){let e=useSyncExternalStore(r=>{let c=effect(()=>{t(),r();});return ()=>c()},()=>t(),()=>t()),o=useCallback(r=>{t(typeof r=="function"?r(t()):r);},[]);return [e,o]}function b(t){return useSyncExternalStore(e=>{let o=effect(()=>{t(),e();});return ()=>o()},()=>t(),()=>t())}function S(t){return useCallback(e=>{t(typeof e=="function"?e(t()):e);},[])}function m(t){useEffect(()=>{let e=effect(t);return ()=>e()},[]);}function g(t,e){let o=l(t);o.has(t)||(o.add(t),t(e));}function v(t){return {value:()=>t(),setValue:o=>{t(typeof o=="function"?o(t()):o);}}}export{W as createComputed,x as createEffect,y as createSignal,v as getSignal,g as useHydrateSignal,S as useSetSignal,V as useSignal,m as useSignalEffect,b as useSignalValue};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactjs-signal",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.6",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "ISC",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"dev": "tsup --watch"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"alien-signals": "^3.
|
|
38
|
+
"alien-signals": "^3.2.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"alien-signals": ">=3.
|
|
41
|
+
"alien-signals": ">=3.2.0",
|
|
42
42
|
"react": ">=18"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|