reactjs-signal 1.1.1 → 1.1.3
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 +1 -1
- package/dist/index.d.ts +21 -17
- package/dist/index.js +1 -1
- package/package.json +31 -41
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ npm install reactjs-signal
|
|
|
25
25
|
|
|
26
26
|
## Devtools
|
|
27
27
|
|
|
28
|
-
- [reactjs-signal-devtools](https://github.com/hunghg255/reactjs-signal-devtools)
|
|
28
|
+
- [reactjs-signal-devtools](https://github.com/hunghg255/reactjs-signal/tree/main/packages/reactjs-signal-devtools)
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* React Alien Signals is a **TypeScript** library that provides hooks built on top of [Alien Signals](https://github.com/stackblitz/alien-signals).
|
|
4
|
+
* It offers a seamless integration with React, ensuring concurrency-safe re-renders without tearing.
|
|
5
|
+
*
|
|
6
|
+
* @module reactjs-signal
|
|
7
|
+
*/
|
|
8
|
+
type TWritableSignal<T> = {
|
|
2
9
|
(): T;
|
|
3
10
|
(value: T): void;
|
|
4
11
|
};
|
|
@@ -13,21 +20,18 @@ type IWritableSignal<T> = {
|
|
|
13
20
|
*
|
|
14
21
|
* @template T - The type of the signal value.
|
|
15
22
|
* @param {T} initialValue - The initial value of the signal.
|
|
16
|
-
* @returns {
|
|
23
|
+
* @returns {TWritableSignal<T>} The created Alien Signal.
|
|
17
24
|
*/
|
|
18
|
-
declare function createSignal<T>(initialValue: T):
|
|
19
|
-
(): T;
|
|
20
|
-
(value: T): void;
|
|
21
|
-
};
|
|
25
|
+
declare function createSignal<T>(initialValue: T): TWritableSignal<T>;
|
|
22
26
|
/**
|
|
23
27
|
* Creates a writable Alien Signal that persists its value in localStorage.
|
|
24
28
|
*
|
|
25
29
|
* @template T - The type of the signal value.
|
|
26
30
|
* @param {string} key - The localStorage key to use for persistence.
|
|
27
31
|
* @param {T} initialValue - The initial value of the signal.
|
|
28
|
-
* @returns {
|
|
32
|
+
* @returns {TWritableSignal<T>} The created Alien Signal.
|
|
29
33
|
*/
|
|
30
|
-
declare function createSignalStorage<T>(key: string, initialValue: T):
|
|
34
|
+
declare function createSignalStorage<T>(key: string, initialValue: T): TWritableSignal<T>;
|
|
31
35
|
/**
|
|
32
36
|
* Creates a computed Alien Signal based on a getter function.
|
|
33
37
|
*
|
|
@@ -72,10 +76,10 @@ declare function createEffect<T>(fn: () => T): () => void;
|
|
|
72
76
|
* ```
|
|
73
77
|
*
|
|
74
78
|
* @template T - The type of the signal value.
|
|
75
|
-
* @param {
|
|
79
|
+
* @param {TWritableSignal<T>} alienSignal - The signal to read/write.
|
|
76
80
|
* @returns {[T, (val: T | ((oldVal: T) => T)) => void]} A tuple [currentValue, setValue].
|
|
77
81
|
*/
|
|
78
|
-
declare function useSignal<T>(alienSignal:
|
|
82
|
+
declare function useSignal<T>(alienSignal: TWritableSignal<T>): [T, (val: T | ((oldVal: T) => T)) => void];
|
|
79
83
|
/**
|
|
80
84
|
* React hook returning only the current value of an Alien Signal (or computed).
|
|
81
85
|
* No setter is provided.
|
|
@@ -92,10 +96,10 @@ declare function useSignal<T>(alienSignal: IWritableSignal<T>): [T, (val: T | ((
|
|
|
92
96
|
* ```
|
|
93
97
|
*
|
|
94
98
|
* @template T - The type of the signal value.
|
|
95
|
-
* @param {
|
|
99
|
+
* @param {TWritableSignal<T>} alienSignal - The signal to read.
|
|
96
100
|
* @returns {T} The current value.
|
|
97
101
|
*/
|
|
98
|
-
declare function useSignalValue<T>(alienSignal:
|
|
102
|
+
declare function useSignalValue<T>(alienSignal: TWritableSignal<T>): T;
|
|
99
103
|
/**
|
|
100
104
|
* React hook returning only a setter function for an Alien Signal.
|
|
101
105
|
* No current value is provided, similar to Jotai's useSetAtom.
|
|
@@ -110,10 +114,10 @@ declare function useSignalValue<T>(alienSignal: IWritableSignal<T>): T;
|
|
|
110
114
|
* ```
|
|
111
115
|
*
|
|
112
116
|
* @template T - The type of the signal value.
|
|
113
|
-
* @param {
|
|
117
|
+
* @param {TWritableSignal<T>} alienSignal - The signal to write.
|
|
114
118
|
* @returns {(val: T | ((oldVal: T) => T)) => void} A setter function.
|
|
115
119
|
*/
|
|
116
|
-
declare function useSetSignal<T>(alienSignal:
|
|
120
|
+
declare function useSetSignal<T>(alienSignal: TWritableSignal<T>): (val: T | ((oldVal: T) => T)) => void;
|
|
117
121
|
/**
|
|
118
122
|
* React hook for running a side effect whenever Alien Signals' dependencies
|
|
119
123
|
* used in `fn` change. The effect is cleaned up on component unmount.
|
|
@@ -138,9 +142,9 @@ declare function useSignalEffect(fn: () => void): void;
|
|
|
138
142
|
* @returns
|
|
139
143
|
*
|
|
140
144
|
* @template T - The type of the signal value.
|
|
141
|
-
* @param {
|
|
145
|
+
* @param {TWritableSignal<T>} alienSignal - The signal to hydrate.
|
|
142
146
|
* @param {T} value - The value to hydrate the signal with.
|
|
143
147
|
*/
|
|
144
|
-
declare function useHydrateSignal<T>(alienSignal:
|
|
148
|
+
declare function useHydrateSignal<T>(alienSignal: TWritableSignal<T>, value: T): void;
|
|
145
149
|
|
|
146
|
-
export { createComputed, createEffect, createSignal, createSignalStorage, useHydrateSignal, useSetSignal, useSignal, useSignalEffect, useSignalValue };
|
|
150
|
+
export { type TWritableSignal, createComputed, createEffect, createSignal, createSignalStorage, useHydrateSignal, useSetSignal, useSignal, useSignalEffect, useSignalValue };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {useSyncExternalStore,useEffect}from'react';import {signal,computed,effect}from'alien-signals';var a=new WeakMap;function l(t){let e=a.get(t);return e||(e=new WeakSet,a.set(t,e)),e}function d(t){return signal(t)}function y(t,e){let o=localStorage.getItem(t),r;if(o)try{r=JSON.parse(o);}catch(c){console.error(`Error parsing localStorage for key "${t}", using initial value.`,c),r=e;}else r=e;let n=d(r);return p(()=>{localStorage.setItem(t,JSON.stringify(n()));}),n}function W(t){return computed(t)}function p(t){return effect(t)}function x(t){return [useSyncExternalStore(r=>{let n=effect(()=>{t(),r();});return ()=>n()},()=>t(),()=>t()),r=>{t(typeof r=="function"?r(t()):r);}]}function b(t){return useSyncExternalStore(e=>{let o=effect(()=>{t(),e();});return ()=>o()},()=>t(),()=>t())}function m(t){return e=>{t(typeof e=="function"?e(t()):e);}}function v(t){useEffect(()=>{let e=effect(t);return ()=>e()},[]);}function V(t,e){let o=l(t);o.has(t)||(o.add(t),t(e));}export{W as createComputed,p as createEffect,d as createSignal,y as createSignalStorage,V as useHydrateSignal,m as useSetSignal,x as useSignal,v as useSignalEffect,b as useSignalValue};
|
package/package.json
CHANGED
|
@@ -1,59 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactjs-signal",
|
|
3
|
-
"version": "1.1.1",
|
|
4
|
-
"description": "",
|
|
5
3
|
"type": "module",
|
|
6
|
-
"
|
|
4
|
+
"version": "1.1.3",
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"homepage": "https://github.com/hunghg255/reactjs-signal#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/hunghg255/reactjs-signal.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/hunghg255/reactjs-signal/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"react",
|
|
18
|
+
"reactjs-signal",
|
|
19
|
+
"devtools"
|
|
20
|
+
],
|
|
7
21
|
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
8
23
|
"exports": {
|
|
9
24
|
".": {
|
|
10
25
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"import": "./dist/index.js"
|
|
13
28
|
}
|
|
14
29
|
},
|
|
15
30
|
"files": [
|
|
16
31
|
"dist"
|
|
17
32
|
],
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"test": "vitest",
|
|
25
|
-
"verify-commit": "verify-commit-msg",
|
|
26
|
-
"prepare": "git-scm-hooks",
|
|
27
|
-
"release": "bumpp -r && npm publish"
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"alien-signals": "^1.0.4"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"alien-signals": ">=1.0.0",
|
|
38
|
+
"react": ">=18"
|
|
28
39
|
},
|
|
29
|
-
"keywords": [],
|
|
30
|
-
"author": "",
|
|
31
|
-
"license": "ISC",
|
|
32
40
|
"devDependencies": {
|
|
33
41
|
"@types/react": "^19.0.2",
|
|
34
|
-
"bumpp": "^9.2.1",
|
|
35
|
-
"git-scm-hooks": "^0.0.7",
|
|
36
42
|
"tsup": "^8.0.1",
|
|
37
|
-
"typescript": "^5.3.3"
|
|
38
|
-
"verify-commit-msg": "^0.0.10"
|
|
39
|
-
},
|
|
40
|
-
"git-hooks": {
|
|
41
|
-
"pre-commit": "npm run lint",
|
|
42
|
-
"commit-msg": "npm run verify-commit"
|
|
43
|
-
},
|
|
44
|
-
"peerDependencies": {
|
|
45
|
-
"react": ">=18",
|
|
46
|
-
"alien-signals": ">=1.0.0"
|
|
47
|
-
},
|
|
48
|
-
"bugs": {
|
|
49
|
-
"url": "https://github.com/hunghg255/reactjs-signal/issues"
|
|
43
|
+
"typescript": "^5.3.3"
|
|
50
44
|
},
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
"url": "git+https://github.com/hunghg255/reactjs-signal.git"
|
|
55
|
-
},
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"alien-signals": "^1.0.1"
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"dev": "tsup --watch"
|
|
58
48
|
}
|
|
59
|
-
}
|
|
49
|
+
}
|