0.1.0 #1
3
bun.lock
3
bun.lock
@@ -13,9 +13,6 @@
|
|||||||
"packages/effect-fc": {
|
"packages/effect-fc": {
|
||||||
"name": "effect-fc",
|
"name": "effect-fc",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
|
||||||
"@typed/async-data": "^0.13.1",
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@effect/language-service": "^0.23.3",
|
"@effect/language-service": "^0.23.3",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -40,8 +40,5 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@effect/language-service": "^0.23.3"
|
"@effect/language-service": "^0.23.3"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@typed/async-data": "^0.13.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import * as AsyncData from "@typed/async-data"
|
|
||||||
import { type Context, Effect, Equivalence, ExecutionStrategy, Exit, type Layer, Option, pipe, PubSub, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
|
import { type Context, Effect, Equivalence, ExecutionStrategy, Exit, type Layer, Option, pipe, PubSub, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { SetStateAction } from "./types/index.js"
|
import { SetStateAction } from "./types/index.js"
|
||||||
@@ -197,29 +196,6 @@ export const useContext: {
|
|||||||
), [scope])
|
), [scope])
|
||||||
})
|
})
|
||||||
|
|
||||||
export const useContextAsync: {
|
|
||||||
<ROut, E, RIn>(
|
|
||||||
layer: Layer.Layer<ROut, E, RIn>,
|
|
||||||
options?: ScopeOptions,
|
|
||||||
): Effect.Effect<AsyncData.AsyncData<Context.Context<ROut>, E>, never, Exclude<RIn, Scope.Scope>>
|
|
||||||
} = Effect.fn("useContextAsync")(function* <ROut, E, RIn>(
|
|
||||||
layer: Layer.Layer<ROut, E, RIn>,
|
|
||||||
options?: ScopeOptions,
|
|
||||||
) {
|
|
||||||
const [context, setContext] = React.useState<AsyncData.AsyncData<Context.Context<ROut>, E>>(AsyncData.noData())
|
|
||||||
|
|
||||||
yield* useFork(() => Effect.sync(() => setContext(AsyncData.loading())).pipe(
|
|
||||||
Effect.andThen(Effect.provide(Effect.context<ROut>(), layer)),
|
|
||||||
Effect.match({
|
|
||||||
onSuccess: v => AsyncData.success(v),
|
|
||||||
onFailure: e => AsyncData.fail(e),
|
|
||||||
}),
|
|
||||||
Effect.andThen(setContext),
|
|
||||||
), [layer], options)
|
|
||||||
|
|
||||||
return context
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
export const useRefFromReactiveValue: {
|
export const useRefFromReactiveValue: {
|
||||||
<A>(value: A): Effect.Effect<SubscriptionRef.SubscriptionRef<A>>
|
<A>(value: A): Effect.Effect<SubscriptionRef.SubscriptionRef<A>>
|
||||||
|
|||||||
Reference in New Issue
Block a user