This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { FetchHttpClient } from "@effect/platform"
|
||||||
|
import { Clipboard, Geolocation, Permissions } from "@effect/platform-browser"
|
||||||
import { createRouter, RouterProvider } from "@tanstack/react-router"
|
import { createRouter, RouterProvider } from "@tanstack/react-router"
|
||||||
import { ReffuseRuntime } from "@thilawyn/reffuse"
|
import { ReffuseRuntime } from "@thilawyn/reffuse"
|
||||||
import { Layer } from "effect"
|
import { Layer } from "effect"
|
||||||
@@ -7,7 +9,12 @@ import { GlobalContext } from "./reffuse"
|
|||||||
import { routeTree } from "./routeTree.gen"
|
import { routeTree } from "./routeTree.gen"
|
||||||
|
|
||||||
|
|
||||||
const layer = Layer.empty
|
const layer = Layer.empty.pipe(
|
||||||
|
Layer.provideMerge(Clipboard.layer),
|
||||||
|
Layer.provideMerge(Geolocation.layer),
|
||||||
|
Layer.provideMerge(Permissions.layer),
|
||||||
|
Layer.provideMerge(FetchHttpClient.layer),
|
||||||
|
)
|
||||||
|
|
||||||
const router = createRouter({ routeTree })
|
const router = createRouter({ routeTree })
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
|
import { HttpClient } from "@effect/platform"
|
||||||
|
import { Clipboard, Geolocation, Permissions } from "@effect/platform-browser"
|
||||||
import { Reffuse, ReffuseContext } from "reffuse"
|
import { Reffuse, ReffuseContext } from "reffuse"
|
||||||
|
|
||||||
|
|
||||||
export const GlobalContext = ReffuseContext.make()
|
export const GlobalContext = ReffuseContext.make<
|
||||||
|
| Clipboard.Clipboard
|
||||||
|
| Geolocation.Geolocation
|
||||||
|
| Permissions.Permissions
|
||||||
|
| HttpClient.HttpClient
|
||||||
|
>()
|
||||||
|
|
||||||
export const R = Reffuse.make(GlobalContext)
|
export const R = Reffuse.make(GlobalContext)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Context, Effect, ExecutionStrategy, Exit, Fiber, Option, Ref, Runtime,
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import * as ReffuseContext from "./ReffuseContext.js"
|
import * as ReffuseContext from "./ReffuseContext.js"
|
||||||
import * as ReffuseRuntime from "./ReffuseRuntime.js"
|
import * as ReffuseRuntime from "./ReffuseRuntime.js"
|
||||||
|
import * as SetStateAction from "./SetStateAction.js"
|
||||||
|
|
||||||
|
|
||||||
export class Reffuse<R> {
|
export class Reffuse<R> {
|
||||||
@@ -271,9 +272,7 @@ export class Reffuse<R> {
|
|||||||
|
|
||||||
const setValue = React.useCallback((setStateAction: React.SetStateAction<A>) =>
|
const setValue = React.useCallback((setStateAction: React.SetStateAction<A>) =>
|
||||||
runSync(Ref.update(ref, previousState =>
|
runSync(Ref.update(ref, previousState =>
|
||||||
typeof setStateAction === "function"
|
SetStateAction.get(setStateAction, previousState)
|
||||||
? (setStateAction as (prevState: A) => A)(previousState)
|
|
||||||
: setStateAction
|
|
||||||
)),
|
)),
|
||||||
[ref])
|
[ref])
|
||||||
|
|
||||||
|
|||||||
12
packages/reffuse/src/SetStateAction.ts
Normal file
12
packages/reffuse/src/SetStateAction.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { Function } from "effect"
|
||||||
|
import type React from "react"
|
||||||
|
|
||||||
|
|
||||||
|
export const get: {
|
||||||
|
<S>(prevState: S): (setStateAction: React.SetStateAction<S>) => S
|
||||||
|
<S>(setStateAction: React.SetStateAction<S>, prevState: S): S
|
||||||
|
} = Function.dual(2, <S>(self: React.SetStateAction<S>, prevState: S): S =>
|
||||||
|
typeof self === "function"
|
||||||
|
? (self as (prevState: S) => S)(prevState)
|
||||||
|
: prevState
|
||||||
|
)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * as Reffuse from "./Reffuse.js"
|
export * as Reffuse from "./Reffuse.js"
|
||||||
export * as ReffuseContext from "./ReffuseContext.js"
|
export * as ReffuseContext from "./ReffuseContext.js"
|
||||||
export * as ReffuseRuntime from "./ReffuseRuntime.js"
|
export * as ReffuseRuntime from "./ReffuseRuntime.js"
|
||||||
|
export * as SetStateAction from "./SetStateAction.js"
|
||||||
|
|||||||
Reference in New Issue
Block a user