0.1.13 #18
@@ -24,6 +24,10 @@ function RouteComponent() {
|
|||||||
|
|
||||||
|
|
||||||
const aRef = R.useRef("a value")
|
const aRef = R.useRef("a value")
|
||||||
|
const anotherRef = R.useRef(69)
|
||||||
|
|
||||||
|
const res = R.useRefsState({ aRef, anotherRef })
|
||||||
|
|
||||||
|
|
||||||
const [reactValue, setReactValue] = useState("initial")
|
const [reactValue, setReactValue] = useState("initial")
|
||||||
const reactValueStream = R.useStreamFromValues([reactValue])
|
const reactValueStream = R.useStreamFromValues([reactValue])
|
||||||
|
|||||||
@@ -411,35 +411,36 @@ export abstract class ReffuseHelpers<R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useRefsState<
|
useRefsState<
|
||||||
Refs extends { [K in keyof Refs]: SubscriptionRef.SubscriptionRef<any> },
|
const Refs extends { readonly [K in keyof Refs]: SubscriptionRef.SubscriptionRef<any> },
|
||||||
R,
|
R,
|
||||||
>(
|
>(
|
||||||
this: ReffuseHelpers<R>,
|
this: ReffuseHelpers<R>,
|
||||||
refs: Refs,
|
refs: Refs,
|
||||||
): {
|
): {
|
||||||
[K in keyof Refs]: readonly [
|
readonly [K in keyof Refs]: readonly [
|
||||||
Effect.Effect<Refs[K]>,
|
Effect.Effect.Success<Refs[K]>,
|
||||||
React.Dispatch<React.SetStateAction<Effect.Effect<Refs[K]>>>,
|
React.Dispatch<React.SetStateAction<Effect.Effect.Success<Refs[K]>>>,
|
||||||
]
|
]
|
||||||
} {
|
} {
|
||||||
const initialState = this.useMemo(() => Effect.Do.pipe(
|
// const initialState = this.useMemo(() => Effect.Do.pipe(
|
||||||
Effect.bindAll(() => refs)
|
// Effect.bindAll(() => refs)
|
||||||
), [], { doNotReExecuteOnRuntimeOrContextChange: true })
|
// ), [], { doNotReExecuteOnRuntimeOrContextChange: true })
|
||||||
|
|
||||||
const [reactStateValue, setReactStateValue] = React.useState(initialState)
|
// const [reactStateValue, setReactStateValue] = React.useState(initialState)
|
||||||
|
|
||||||
this.useFork(() => Stream.runForEach(
|
// this.useFork(() => Stream.runForEach(
|
||||||
Stream.changesWith(ref.changes, (x, y) => x === y),
|
// Stream.changesWith(ref.changes, (x, y) => x === y),
|
||||||
v => Effect.sync(() => setReactStateValue(v)),
|
// v => Effect.sync(() => setReactStateValue(v)),
|
||||||
), [ref])
|
// ), [ref])
|
||||||
|
|
||||||
const setValue = this.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
|
// const setValue = this.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
|
||||||
Ref.update(ref, prevState =>
|
// Ref.update(ref, prevState =>
|
||||||
SetStateAction.value(setStateAction, prevState)
|
// SetStateAction.value(setStateAction, prevState)
|
||||||
),
|
// ),
|
||||||
[ref])
|
// [ref])
|
||||||
|
|
||||||
return [reactStateValue, setValue]
|
// return [reactStateValue, setValue]
|
||||||
|
return null!
|
||||||
}
|
}
|
||||||
|
|
||||||
useStreamFromValues<const A extends React.DependencyList, R>(
|
useStreamFromValues<const A extends React.DependencyList, R>(
|
||||||
|
|||||||
Reference in New Issue
Block a user