A simple reactive system for your Javascript application. Zero dependency, TypeScript fully supported.
-[JS Signals proposal](https://github.com/tc39/proposal-signals) is currently in Stage 1. This package draws strong inspiration from [KnockoutJS](https://github.com/knockout/knockout)'s concepts and [SolidJS](https://github.com/solidjs)'s Signal, enabling us to use Signals in vanilla JavaScript.
+This package draws strong inspiration from [KnockoutJS](https://github.com/knockout/knockout)'s concepts and [SolidJS](https://github.com/solidjs)'s Signal, enabling us to use Signals in vanilla JavaScript. [JS Signals proposal](https://github.com/tc39/proposal-signals) is currently in Stage 1.
## Docs
@@ -16,7 +16,7 @@
## Run this monorepo locally
-Please check the root `package.json`'s `engines` field for the env requirement, then run:
+Please check the root [`package.json`](https://github.com/kaisergeX/signal-proxy/blob/main/package.json#L29)'s `engines` field for the env requirement, then run:
```
pnpm i
diff --git a/apps/playground/src/hooks/react-signal.ts b/apps/playground/src/hooks/react-signal.ts
index c3c8d2e..76fdc26 100644
--- a/apps/playground/src/hooks/react-signal.ts
+++ b/apps/playground/src/hooks/react-signal.ts
@@ -43,15 +43,21 @@ export function useSignal(
}
/**
- * Signal effect inside a React component.
+ * Signal effect inside React component.
+ * ___
+ * ⚠️ [Experimental] Implementation of React adapter. **DO NOT** use in production. Known issues:
+ * - Some devices has this issue: When there're `N` (N>1) `useSignalEffect` in 1 component, each tracking a diff Signal, and only 1 Signal changes, those effects sometime trigger `N` times.
+ * No idea. The issue might be occurring because of multiple empty deps useEffect.
+ * Reproduce?: Playground page - Hit the "`Local multiplier 4x`" button multiple times
+ *
* @param effect Imperative function that will run whenever dependencies change. Dependencies are Signals that are used inside the Effect itself.
*/
export const useSignalEffect = (effect: SignalEffect) => {
- const [_, forceUpdate] = useReducer((x) => x + 1, 0);
+ // const [_, forceUpdate] = useReducer((x) => x + 1, 0);
useEffect(() => {
const cleanupEffect = createEffect(effect);
- forceUpdate();
+ // forceUpdate();
return () => cleanupEffect();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
diff --git a/apps/playground/src/routes/signal/-components/PlaygroundChild3.tsx b/apps/playground/src/routes/signal/-components/PlaygroundChild3.tsx
index a57b266..210c9ad 100644
--- a/apps/playground/src/routes/signal/-components/PlaygroundChild3.tsx
+++ b/apps/playground/src/routes/signal/-components/PlaygroundChild3.tsx
@@ -6,20 +6,20 @@ const [globalCount] = playgroundSignal;
createEffect(() => {
console.log(
- '%c[createEffect] PlaygroundChild3',
+ '%c[createEffect] Child3',
'color: #f9fafb; background-color: #0ea5e9;',
- `Global Signal value = ${globalCount()}`,
+ `globalCount = ${globalCount()}`,
);
});
const PlaygroundChild3 = () => {
- const computedCount = useComputed(globalCount);
+ const doubledGlobalCount = useComputed(() => globalCount() * 2);
return (
PlaygroundChild 3
-
Global Signal value: {computedCount()}
+ Global count doubled value: {doubledGlobalCount()}