reactjs-signal 1.1.0 → 1.1.1

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.
Files changed (3) hide show
  1. package/README.md +10 -61
  2. package/dist/index.js +1 -1
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -15,12 +15,17 @@
15
15
  <a href="https://github.com/hunghg255/reactjs-signal/blob/main/LICENSE" target="_blank" rel="noopener noreferrer"><img src="https://badgen.net/github/license/hunghg255/reactjs-signal" alt="License" /></a>
16
16
  </p>
17
17
 
18
+
19
+
18
20
  ## Installation
19
21
 
20
22
  ```bash
21
23
  npm install reactjs-signal
22
24
  ```
23
25
 
26
+ ## Devtools
27
+
28
+ - [reactjs-signal-devtools](https://github.com/hunghg255/reactjs-signal-devtools)
24
29
 
25
30
  ## Usage
26
31
 
@@ -50,7 +55,7 @@ Creates a writable Alien Signal.
50
55
 
51
56
  ```typescript
52
57
  const countSignal = createSignal(0);
53
- countSignal.set(10); // sets the value to 10
58
+ countSignal(10); // sets the value to 10
54
59
  ```
55
60
 
56
61
  #### Parameters
@@ -69,7 +74,7 @@ Creates a computed Alien Signal based on a getter function.
69
74
 
70
75
  ```typescript
71
76
  const countSignal = createSignal(1);
72
- const doubleSignal = createComputed(() => countSignal.get() * 2);
77
+ const doubleSignal = createComputed(() => countSignal() * 2);
73
78
  ```
74
79
 
75
80
  #### Parameters
@@ -80,43 +85,6 @@ const doubleSignal = createComputed(() => countSignal.get() * 2);
80
85
 
81
86
  - `ISignal<T>`: The created computed signal.
82
87
 
83
- ### `createEffect`
84
-
85
- Creates a side effect in Alien Signals.
86
-
87
- #### Example
88
-
89
- ```typescript
90
- const countSignal = createSignal(1);
91
- createEffect(() => {
92
- console.log('Count is', countSignal.get());
93
- });
94
- ```
95
-
96
- #### Parameters
97
-
98
- - `fn` (`() => T`): A function that will run whenever its tracked signals update.
99
-
100
- #### Returns
101
-
102
- - `Effect<T>`: The created effect object.
103
-
104
- ### `createSignalScope`
105
-
106
- Creates an Alien Signals effect scope. This scope can manage multiple effects, allowing you to stop or start them together.
107
-
108
- #### Example
109
-
110
- ```typescript
111
- const scope = createSignalScope();
112
- scope.run(() => {
113
- // create effects in here...
114
- });
115
- ```
116
-
117
- #### Returns
118
-
119
- - `EffectScope`: The created effect scope.
120
88
 
121
89
  ### `useSignal`
122
90
 
@@ -148,7 +116,7 @@ React hook returning only the current value of an Alien Signal (or computed). No
148
116
 
149
117
  ```typescript
150
118
  const countSignal = createSignal(0);
151
- const doubleSignal = createComputed(() => countSignal.get() * 2);
119
+ const doubleSignal = createComputed(() => countSignal() * 2);
152
120
  function Display() {
153
121
  const count = useSignalValue(countSignal);
154
122
  const double = useSignalValue(doubleSignal);
@@ -195,7 +163,7 @@ React hook for running a side effect whenever Alien Signals' dependencies used i
195
163
  ```typescript
196
164
  function Logger() {
197
165
  useSignalEffect(() => {
198
- console.log('Signal changed:', someSignal.get());
166
+ console.log('Signal changed:', someSignal());
199
167
  });
200
168
  return null;
201
169
  }
@@ -205,25 +173,6 @@ function Logger() {
205
173
 
206
174
  - `fn` (`() => void`): The effect function to run.
207
175
 
208
- ### `useSignalScope`
209
-
210
- React hook for managing an Alien Signals effect scope. All signals/effects created inside this scope run when the component mounts, and are stopped automatically when the component unmounts.
211
-
212
- #### Example
213
-
214
- ```typescript
215
- function ScopedEffects() {
216
- const scope = useSignalScope();
217
- useEffect(() => {
218
- scope.run(() => {
219
- createEffect(() => {
220
- console.log('Scoped effect:', someSignal.get());
221
- });
222
- });
223
- }, [scope]);
224
- return null;
225
- }
226
- ```
227
176
 
228
177
  <!-- /**
229
178
  * React hook to initialize a signal with a value when hydrating from server.
@@ -236,7 +185,7 @@ function ScopedEffects() {
236
185
  * @param {T} value - The value to hydrate the signal with.
237
186
  */
238
187
  export function useHydrateSignal<T>(alienSignal: IWritableSignal<T>, value: T): void {
239
- alienSignal.set(value);
188
+ alienSignal(value);
240
189
  } -->
241
190
 
242
191
  ### `useHydrateSignal`
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import {signal,computed,effect}from'alien-signals';import {useSyncExternalStore,useEffect}from'react';var u=new WeakMap,l=e=>{let t=u.get(e);return t||(t=new WeakSet,u.set(e,t)),t};function d(e){return signal(e)}function x(e,t){let o=localStorage.getItem(e),r;if(o)try{r=JSON.parse(o);}catch(T){console.error(`Error parsing localStorage for key "${e}", using initial value.`,T),r=t;}else r=t;let n=d(r);return p(()=>{localStorage.setItem(e,JSON.stringify(n()));}),n}function b(e){return computed(e)}function p(e){return effect(e)}function m(e){return [useSyncExternalStore(r=>{let n=effect(()=>{e(),r();});return ()=>n()},()=>e(),()=>e()),r=>{e(typeof r=="function"?r(e()):r);}]}function v(e){return useSyncExternalStore(t=>{let o=effect(()=>{e(),t();});return ()=>o()},()=>e(),()=>e())}function V(e){return t=>{e(typeof t=="function"?t(e()):t);}}function h(e){useEffect(()=>{let t=effect(e);return ()=>t()},[e]);}function E(e,t){let o=l(e);o.has(e)||(o.add(e),e(t));}export{b as createComputed,p as createEffect,d as createSignal,x as createSignalStorage,E as useHydrateSignal,V as useSetSignal,m as useSignal,h as useSignalEffect,v as useSignalValue};
1
+ import {signal,computed,effect}from'alien-signals';import {useSyncExternalStore,useEffect}from'react';var u=new WeakMap,l=t=>{let e=u.get(t);return e||(e=new WeakSet,u.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 I(t){return [useSyncExternalStore(r=>{let n=effect(()=>{t(),r();});return ()=>n()},()=>t(),()=>t()),r=>{t(typeof r=="function"?r(t()):r);}]}function x(t){return useSyncExternalStore(e=>{let o=effect(()=>{t(),e();});return ()=>o()},()=>t(),()=>t())}function b(t){return e=>{t(typeof e=="function"?e(t()):e);}}function m(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,b as useSetSignal,I as useSignal,m as useSignalEffect,x as useSignalValue};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactjs-signal",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -42,7 +42,8 @@
42
42
  "commit-msg": "npm run verify-commit"
43
43
  },
44
44
  "peerDependencies": {
45
- "react": ">=18"
45
+ "react": ">=18",
46
+ "alien-signals": ">=1.0.0"
46
47
  },
47
48
  "bugs": {
48
49
  "url": "https://github.com/hunghg255/reactjs-signal/issues"