0.1.3 (#5)
All checks were successful
Publish / publish (push) Successful in 24s
Lint / lint (push) Successful in 16s

Co-authored-by: Julien Valverdé <julien.valverde@mailo.com>
Reviewed-on: https://gitea:3000/Thilawyn/reffuse/pulls/5
This commit was merged in pull request #5.
This commit is contained in:
Julien Valverdé
2025-03-11 01:44:37 +01:00
parent 2aa0c64a7c
commit a7b5a32071
28 changed files with 707 additions and 109 deletions

View File

@@ -4,6 +4,6 @@ Extension to integrate `@typed/lazy-ref` with Reffuse.
## Peer dependencies
- `@typed/lazy-ref`
- `reffuse` 0.1.2+
- `reffuse` 0.1.3+
- `effect` 3.13+
- `react` & `@types/react` 19+

View File

@@ -25,7 +25,6 @@
"build": "tsc",
"lint:tsc": "tsc --noEmit",
"pack": "npm pack",
"publish": "npm publish --access public",
"clean:cache": "rm -f tsconfig.tsbuildinfo",
"clean:dist": "rm -rf dist",
"clean:node": "rm -rf node_modules"
@@ -34,10 +33,10 @@
"reffuse": "workspace:*"
},
"peerDependencies": {
"@typed/lazy-ref": "^0.3.3",
"@typed/lazy-ref": "^0.3.0",
"@types/react": "^19.0.0",
"effect": "^3.13.0",
"react": "^19.0.0",
"reffuse": "^0.1.2"
"reffuse": "^0.1.3"
}
}

View File

@@ -9,19 +9,17 @@ export const LazyRefExtension = ReffuseExtension.make(() => ({
this: ReffuseHelpers.ReffuseHelpers<R>,
ref: LazyRef.LazyRef<A, E, R>,
): [A, React.Dispatch<React.SetStateAction<A>>] {
const runSync = this.useRunSync()
const initialState = React.useMemo(() => runSync(ref), [])
const initialState = this.useMemo(() => ref, [], { doNotReExecuteOnRuntimeOrContextChange: true })
const [reactStateValue, setReactStateValue] = React.useState(initialState)
this.useFork(() => Stream.runForEach(ref.changes, v => Effect.sync(() =>
setReactStateValue(v)
)), [ref])
const setValue = React.useCallback((setStateAction: React.SetStateAction<A>) =>
runSync(LazyRef.update(ref, prevState =>
const setValue = this.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
LazyRef.update(ref, prevState =>
SetStateAction.value(setStateAction, prevState)
)),
),
[ref])
return [reactStateValue, setValue]