Dependencies fix
All checks were successful
Lint / lint (push) Successful in 11s

This commit is contained in:
Julien Valverdé
2025-02-18 01:08:26 +01:00
parent 1b1a1961bc
commit a7a0951b61
8 changed files with 839 additions and 41 deletions

View File

@@ -16,27 +16,30 @@
"@tanstack/router-devtools": "^1.105.0",
"@tanstack/router-plugin": "^1.105.0",
"@thilawyn/thilaschema": "^0.1.4",
"@types/react": "^19.0.9",
"@types/react-dom": "^19.0.3",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@vitejs/plugin-react": "^4.3.4",
"effect": "^3.13.1",
"eslint": "^9.20.1",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^15.15.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"reffuse": "workspace:*",
"typescript-eslint": "^8.24.0",
"typescript-eslint": "^8.24.1",
"vite": "^6.1.0"
},
"dependencies": {
"@effect/platform": "^0.77.1",
"@effect/platform-browser": "^0.56.1",
"@effect/platform": "~0.77.1",
"@effect/platform-browser": "~0.56.1",
"@radix-ui/themes": "^3.2.0",
"@typed/id": "^0.17.1",
"@typed/lazy-ref": "^0.3.3",
"effect": "~3.13.1",
"lucide-react": "^0.475.0",
"mobx": "^6.13.6"
"mobx": "^6.13.6",
"reffuse": "workspace:*"
},
"overrides": {
"effect": "~3.13.1"
}
}

View File

@@ -1,6 +1,6 @@
import { R } from "@/reffuse"
import { createFileRoute } from "@tanstack/react-router"
import { DateTime, Ref, Schedule, Stream } from "effect"
import { DateTime, Effect, Ref, Schedule, Stream, SubscriptionRef } from "effect"
const timeEverySecond = Stream.repeatEffectWithSchedule(
@@ -15,7 +15,7 @@ export const Route = createFileRoute("/time")({
function Time() {
const timeRef = R.useRefFromEffect(DateTime.now)
const timeRef = R.useMemo(DateTime.now.pipe(Effect.flatMap(SubscriptionRef.make)))
R.useFork(Stream.runForEach(timeEverySecond, v => Ref.set(timeRef, v)), [timeRef])
const [time] = R.useRefState(timeRef)

View File

@@ -1,6 +1,6 @@
import { Todo } from "@/domain"
import { Box, Button, Card, Flex, TextArea } from "@radix-ui/themes"
import { Effect, Option } from "effect"
import { Effect, Option, SubscriptionRef } from "effect"
import { R } from "../reffuse"
import { TodosState } from "../services"
@@ -17,7 +17,7 @@ export function VNewTodo() {
}, true))
)
const todoRef = R.useRefFromEffect(createEmptyTodo)
const todoRef = R.useMemo(createEmptyTodo.pipe(Effect.flatMap(SubscriptionRef.make)))
const [todo, setTodo] = R.useRefState(todoRef)

View File

@@ -29,9 +29,8 @@
"clean:node": "rm -rf node_modules"
},
"devDependencies": {
"@typed/lazy-ref": "^0.3.3",
"@types/react": "^19.0.9",
"effect": "^3.13.1",
"@types/react": "^19.0.10",
"effect": "~3.13.1",
"react": "^19.0.0"
}
}

View File

@@ -1,4 +1,3 @@
import * as LazyRef from "@typed/lazy-ref"
import { Context, Effect, ExecutionStrategy, Exit, Fiber, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
import React from "react"
import * as ReffuseContext from "./ReffuseContext.js"
@@ -115,12 +114,12 @@ export class Reffuse<R> {
const [value, setValue] = React.useState(initialValue)
React.useEffect(() => {
const closeInitialScope = Scope.close(initialScope, Exit.void).pipe(
const closeInitialScopeIfNeeded = Scope.close(initialScope, Exit.void).pipe(
Effect.andThen(Effect.sync(() => { initialScopeClosed.current = true })),
Effect.when(() => !initialScopeClosed.current),
)
const [scope, value] = closeInitialScope.pipe(
const [scope, value] = closeInitialScopeIfNeeded.pipe(
Effect.andThen(Scope.make(options?.finalizerExecutionStrategy).pipe(
Effect.flatMap(scope => effect.pipe(
Effect.provideService(Scope.Scope, scope),
@@ -332,14 +331,6 @@ export class Reffuse<R> {
)
}
useRefFromEffect<A, E>(effect: Effect.Effect<A, E, R>): SubscriptionRef.SubscriptionRef<A> {
return this.useMemo(
effect.pipe(Effect.flatMap(SubscriptionRef.make)),
[],
{ doNotReExecuteOnRuntimeOrContextChange: false }, // Do not recreate the ref when the context changes
)
}
/**
* Binds the state of a `SubscriptionRef` to the state of the React component.
*
@@ -373,24 +364,24 @@ export class Reffuse<R> {
*
* Note that the rules of React's immutable state still apply: updating a ref with the same value will not trigger a re-render.
*/
useLazyRefState<A, E>(ref: LazyRef.LazyRef<A, E, R>): [A, React.Dispatch<React.SetStateAction<A>>] {
const runSync = this.useRunSync()
// useLazyRefState<A, E>(ref: LazyRef.LazyRef<A, E, R>): [A, React.Dispatch<React.SetStateAction<A>>] {
// const runSync = this.useRunSync()
const initialState = React.useMemo(() => runSync(ref), [])
const [reactStateValue, setReactStateValue] = React.useState(initialState)
// const initialState = React.useMemo(() => runSync(ref), [])
// const [reactStateValue, setReactStateValue] = React.useState(initialState)
this.useFork(Stream.runForEach(ref.changes, v => Effect.sync(() =>
setReactStateValue(v)
)), [ref])
// 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 =>
SetStateAction.value(setStateAction, prevState)
)),
[ref])
// const setValue = React.useCallback((setStateAction: React.SetStateAction<A>) =>
// runSync(LazyRef.update(ref, prevState =>
// SetStateAction.value(setStateAction, prevState)
// )),
// [ref])
return [reactStateValue, setValue]
}
// return [reactStateValue, setValue]
// }
}