ui/effect
ui/effect
此内容目前仅提供英文版。
导入自 @norbital-ai/ui/effect
@norbital-ai/ui/effect: the one Svelte edge. A page's Effects run on the browser runtime its mount creates (mount_edge(ManagedRuntime.make(ShellLive)) in the shell, the root layout in a host app): run hands {#await} a Promise, fork runs an event handler's effect, observe owns streamed state and attach runs a scoped fiber for an element's lifetime. Every fiber runs in the mounted runtime's scope, so unmounting interrupts them all.
index
QueryOptions type
type QueryOptions<A> = {
readonly initial?: NoInfer<A>;
}; A server answer may seed the first render and hydration, never a later query scope.
成员
| 名称 | 类型 | 说明 |
|---|---|---|
initial? | NoInfer<A> |
源码: packages/ui/src/effect/index.ts:95
attach function
function attach<N extends Element>(f: (node: N) => Effect.Effect<unknown, never, Scope.Scope>): Attachment<N> {@attach attach((node) => effect)}: the effect runs scoped for the element's lifetime, interrupted when it leaves.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
f | (node: N) => Effect.Effect<unknown, never, Scope.Scope> |
源码: packages/ui/src/effect/index.ts:351
fork function
function fork<A>(effect: Effect.Effect<A>): void
function fork<A, E>(effect: Effect.Effect<A, E>, onFailure: (error: E) => void): void For an event handler: runs the effect; onFailure receives its failure, and the type requires it when one can occur.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
effect | Effect.Effect<A> |
源码: packages/ui/src/effect/index.ts:73
mount_edge function
function mount_edge<R, E>(runtime: ManagedRuntime.ManagedRuntime<R, E>): () => Promise<void> Binds the edge to a mount's runtime (the latest mount wins). The returned function disposes the runtime, which interrupts every fiber still running on it and waits for them.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
runtime | ManagedRuntime.ManagedRuntime<R, E> |
源码: packages/ui/src/effect/index.ts:31
observe function
function observe<A, E>(source: () => Stream.Stream<A, E> | null, options?: QueryOptions<A>): QueryState<A, E> A live read in a component (call it while the component initializes): the stream source() names, or none for null. A change of its reactive inputs subscribes the new stream from empty; teardown interrupts the fiber.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
source | () => Stream.Stream<A, E> | null | |
options? | QueryOptions<A> |
源码: packages/ui/src/effect/index.ts:115
observe_once function
function observe_once<A, E>(source: () => Effect.Effect<A, E> | null, options?: QueryOptions<A>): QueryState<A, E> A one-shot read composes into the same state and lifetime as a live query.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
source | () => Effect.Effect<A, E> | null | |
options? | QueryOptions<A> |
源码: packages/ui/src/effect/index.ts:213
reactive_clock function
function reactive_clock<T extends object>(snapshot: (at: Date) => T, unit?: "minute" | "hour" | "day", zone?: string, now?: () => Date): T A visible-page clock ticks at calendar boundaries in the workspace's zone; no unit is a fixed snapshot.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
snapshot | (at: Date) => T | |
unit? | 'minute' | 'hour' | 'day' | |
zone? | string | |
now? | () => Date |
源码: packages/ui/src/effect/index.ts:288
reactive_query function
function reactive_query<A, E>(effect: Effect.Effect<A, E>, stream: Stream.Stream<Result.Result<A, E>>, initial?: Option.Option<A>): Effect.Effect<A, E, never> & { readonly current: A | undefined; readonly loading: boolean; readonly error: E | undefined; readonly then: Promise<A>["then"]; } A query's component reads subscribe; its Promise and Effect edges read once outside component reactivity.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
effect | Effect.Effect<A, E> | |
stream | Stream.Stream<Result.Result<A, E>> | |
initial? | Option.Option<A> |
源码: packages/ui/src/effect/index.ts:224
run function
function run<A, E>(effect: Effect.Effect<A, E>): Promise<A> For {#await run(effect)}: resolves with the success, rejects with the tagged failure for {:catch} to render.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
effect | Effect.Effect<A, E> |
源码: packages/ui/src/effect/index.ts:62
running_fibers function
function running_fibers(): number Fibers started through any edge and not yet ended: the mount/unmount leak check reads it.