effect/ui: write public types out instead of aliasing them (#10590)

This commit is contained in:
Tim
2026-11-13 16:58:19 +13:00
parent 4feb4462da
commit f362f23378
18 changed files with 222 additions and 308 deletions
+12 -37
View File
@@ -185,24 +185,15 @@ export type GroupField<In> =
& string
/**
* The `group` fields of a Command's args: what `Command.interrupt` and
* `h.isRunning` take to address one group.
* The optional group argument of `Command.interrupt` and `h.isRunning`: the
* `group` fields of the Command's args, or none for a Command without a
* `group`.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type GroupPick<Args, G extends string> = Pick<Args, G & keyof Args>
/**
* The optional group argument of `Command.interrupt` and `h.isRunning`: none
* for a Command without a `group`.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type GroupArg<Args, G extends string> = [G] extends [never] ? [] : [group?: GroupPick<Args, G>]
export type GroupArg<Args, G extends string> = [G] extends [never] ? [] : [group?: Pick<Args, G & keyof Args>]
/**
* The arguments of `make`: optional when every field of the args is.
@@ -417,9 +408,9 @@ export type Kind = "Effect" | "Stream"
* the success of the Command's definition before any `map`, and `SourceE`
* its typed failure before `match`; they're what a story's `resolve` and
* `fail` steps take. `K` is the kind, which decides whether `effect` or
* `stream` holds the work; the other field is `undefined`. Use the
* `Effectful` and `Streaming` aliases rather than naming `K` yourself, and
* narrow a `Command` on `_tag` before reading the work.
* `stream` holds the work; the other field is `undefined`: `"Effect"` for a
* Command whose result is one message, `"Stream"` for one declared with
* `stream: true`. Narrow a `Command` on `_tag` before reading the work.
*
* One interface for both kinds, rather than two, is what lets
* `command.pipe(Command.map((result) => ...))` infer `result`.
@@ -472,24 +463,6 @@ export interface Unmatched<out A, out E, out R, out K extends Kind> extends Pipe
readonly stream: K extends "Stream" ? Stream.Stream<A, E, R> : undefined
}
/**
* A Command whose result is one message.
*
* @stability experimental
* @category models
* @since 4.1.5
*/
export type Effectful<Msg, R = never, Source = Msg, SourceE = never> = Issued<Msg, R, Source, "Effect", SourceE>
/**
* A Command declared with `stream: true`, whose result is a Stream of messages.
*
* @stability experimental
* @category models
* @since 4.1.5
*/
export type Streaming<Msg, R = never, Source = Msg, SourceE = never> = Issued<Msg, R, Source, "Stream", SourceE>
/**
* A Command that interrupts the running and queued runs of another Command.
*
@@ -526,7 +499,7 @@ export interface Interrupt extends Pipeable.Pipeable {
* @category models
* @since 4.1.5
*/
export type Command<Msg, R = never> = Effectful<Msg, R, never, never> | Streaming<Msg, R, never, never> | Interrupt
export type Command<Msg, R = never> = Issued<Msg, R, never, "Effect"> | Issued<Msg, R, never, "Stream"> | Interrupt
/**
* The requirements of a Command, or of a union of them.
@@ -674,7 +647,9 @@ export declare namespace Definition {
export interface Factory<in out Args, in out Msg, out IsStream extends boolean = false, out G extends string = never>
extends Definition<Args, Msg, IsStream, never, G>
{
(...args: MakeArgs<Args>): IsStream extends true ? Streaming<Msg> : Effectful<Msg>
(
...args: MakeArgs<Args>
): IsStream extends true ? Issued<Msg, never, Msg, "Stream"> : Issued<Msg, never, Msg, "Effect">
readonly name: string
/** The args Schema. */
readonly args: Schema.Top
@@ -719,7 +694,7 @@ export interface Service<
*/
make(
...args: MakeArgs<Args>
): [Err] extends [never] ? (IsStream extends true ? Streaming<A, Self> : Effectful<A, Self>)
): [Err] extends [never] ? (IsStream extends true ? Issued<A, Self, A, "Stream"> : Issued<A, Self, A, "Effect">)
: Unmatched<A, Err, Self, IsStream extends true ? "Stream" : "Effect">
}
+61 -95
View File
@@ -218,7 +218,7 @@ export interface Update<in out Model, in out Msg, in out Events, out Props, L =
{
readonly props: Props
/** The loaders' results, as `h.loaded` shows them for the Model before this `update`. */
readonly loaded: Loaded<L>
readonly loaded: { readonly [K in keyof L]: LoadedOf<L[K]> }
}
/**
@@ -420,18 +420,36 @@ export interface Component<
}
/**
* What `h` gains in `view` for a component with loaders: `loaded`,
* `previous` and `patched`. `previous` and `patched` have no `loadMany`
* loader.
* What `h` gains in `view` for a component with loaders.
*
* **Details**
*
* `loaded` holds each loader's result, as `$.loaded` does in `update`.
*
* `previous` holds, per single or list loader, the Success value its slot
* holds for args other than the loader's current ones. It's `Some` only while
* the loader is enabled, so it is `None` whenever `h.loaded` has the stored
* result.
*
* `patched` tells, per single or list loader, whether the value includes an
* optimistic patch the server hasn't confirmed. It is per entry, not per
* instance.
*
* `previous` and `patched` have no `loadMany` loader.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type LoaderHelpers<L> = [keyof L] extends [never] ? {} : {
readonly loaded: Loaded<L>
readonly previous: Previous<L>
readonly patched: Patched<L>
readonly loaded: { readonly [K in keyof L]: LoadedOf<L[K]> }
readonly previous: {
readonly [K in SingleNames<L>]: L[K] extends Load<infer R> ?
R extends Loader.ListRead.Any ? Option.Option<Omit<LoadedList<R>, "more">>
: Option.Option<Loader.Read.Success<R>>
: never
}
readonly patched: { readonly [K in SingleNames<L>]: boolean }
}
/**
@@ -527,20 +545,6 @@ export interface LoadMany<out R extends Loader.Read.Any> {
*/
export type LoaderSpec = { readonly [name: string]: Load<any> | LoadMany<any> }
/**
* The `LoaderSpec` `make` infers from `loaders`: `S` holds each entry's
* `load` and `M` each entry's `loadMany`.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type SpecOf<S, M> = {
readonly [K in keyof S]: M[K & keyof M] extends Loader.Read.Any ? LoadMany<M[K & keyof M]>
: S[K] extends Loader.Read.Any ? Load<S[K]>
: never
}
// A `load` beside a `loadMany` in one entry, or a list read under `loadMany`, is rejected.
type OneRead<M> = [M] extends [Loader.Read.Any] ? { readonly "~error": "an entry takes one of load and loadMany" }
: unknown
@@ -586,24 +590,6 @@ export type ListNames<L> =
*/
export type KeyedNames<L> = { readonly [K in keyof L]: L[K] extends LoadMany<any> ? K : never }[keyof L] & string
/**
* The read of a `Load` or a `LoadMany`.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type ReadOf<D> = D extends Load<infer R> ? R : D extends LoadMany<infer R> ? R : never
/**
* The result a read opens to: an `AsyncResult` of its success and error.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type ResultOf<R> = AsyncResult.AsyncResult<Loader.Read.Success<R>, Loader.Read.Error<R>>
/**
* The services a component's loaders add to its requirements: the reads
* themselves, never what their fetchers use.
@@ -612,13 +598,21 @@ export type ResultOf<R> = AsyncResult.AsyncResult<Loader.Read.Success<R>, Loader
* @category utility types
* @since 4.1.5
*/
export type LoaderServices<L> = ServiceOf<ReadOf<L[keyof L]>>
export type LoaderServices<L> = ServiceOf<L[keyof L]>
type ServiceOf<R> = R extends { readonly Identifier: infer Self } ? Self : never
type ServiceOf<D> = D extends { readonly read: { readonly Identifier: infer Self } } ? Self : never
/**
* One loader opened: a single read's result, a list's result opened to
* `LoadedList`, or a keyed read's entries.
* One loader as `h.loaded`, `$.loaded`, and the `loaded` argument of `head`,
* `subscriptions` and a loader's `args` open it.
*
* **Details**
*
* A single loader opens to an `AsyncResult` of its read's success and error,
* a list loader to an `AsyncResult` of its `LoadedList`, and a `loadMany`
* loader to its entries in the order of its args. A single or list loader
* holds the result its slot took at the loader's current args, and otherwise
* `Initial`, waiting while the loader is enabled.
*
* @stability experimental
* @category utility types
@@ -627,26 +621,9 @@ type ServiceOf<R> = R extends { readonly Identifier: infer Self } ? Self : never
export type LoadedOf<D> = D extends LoadMany<infer R> ? KeyedLoaded<R>
: D extends Load<infer R> ?
R extends Loader.ListRead.Any ? AsyncResult.AsyncResult<LoadedList<R>, Loader.Read.Error<R>>
: ResultOf<R>
: AsyncResult.AsyncResult<Loader.Read.Success<R>, Loader.Read.Error<R>>
: never
/**
* `h.loaded` in `view`, `$.loaded` in `update`, and `loaded` in `head`,
* `subscriptions` and a loader's `args`.
*
* **Details**
*
* Per single or list loader, the result its slot holds when that was taken
* at the loader's current args, and otherwise `Initial`, waiting while the
* loader is enabled. A `loadMany` loader opens to its entries in the order
* of its args.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type Loaded<L> = { readonly [K in keyof L]: LoadedOf<L[K]> }
/**
* A list loader as `h.loaded` opens it, inside its `AsyncResult`.
*
@@ -712,33 +689,6 @@ export interface KeyedChange<R extends Loader.Read.Any> {
readonly result: AsyncResult.AsyncResult<Loader.Read.Success<R>, Loader.Read.Error<R>>
}
/**
* `h.previous` in `view`: per single or list loader, the Success value its
* slot holds for args other than the loader's current ones. `Some` only while
* the loader is enabled, so it is `None` whenever `h.loaded` has the stored
* result.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type Previous<L> = {
readonly [K in SingleNames<L>]: ReadOf<L[K]> extends infer R extends Loader.ListRead.Any
? Option.Option<Omit<LoadedList<R>, "more">>
: Option.Option<Loader.Read.Success<ReadOf<L[K]>>>
}
/**
* `h.patched` in `view`: per single or list loader, whether the value
* includes an optimistic patch the server hasn't confirmed. It is per entry,
* not per instance.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type Patched<L> = { readonly [K in SingleNames<L>]: boolean }
/**
* What a loader's `args` returns: the args of a `load`'s read, or
* `undefined` to disable it, and an array of args for a `loadMany`, empty
@@ -915,6 +865,13 @@ export const make = <
Events = never,
S = {},
M = {},
// The loaders as `Load` and `LoadMany` entries, by name. Nothing infers it, so it's always this default:
// the mapped types over it use `NoInfer`, or an annotated `loaded` argument would.
L = {
readonly [K in keyof S]: M[K & keyof M] extends Loader.Read.Any ? LoadMany<M[K & keyof M]>
: S[K] extends Loader.Read.Any ? Load<S[K]>
: never
},
UI extends Model | InitStep<Model, Msg, Events, any> = Model,
U extends Model | Step<Model, Msg, Events, any, any> = Model,
UV extends View.Content<Msg, any> = View.Node<Msg>,
@@ -936,7 +893,7 @@ export const make = <
readonly args: (
model: Model,
props: Props,
loaded: Omit<Loaded<SpecOf<S, M>>, K>
loaded: { readonly [P in Exclude<keyof NoInfer<L>, K>]: LoadedOf<NoInfer<L>[P]> }
) => ArgsFor<S[K], M[K & keyof M]>
readonly debounce?: Duration.Input | undefined
readonly onChange?: OnChange<S[K], M[K & keyof M], NoInfer<Msg>> | undefined
@@ -946,15 +903,24 @@ export const make = <
)
| undefined
readonly init: ($: Init<Model, Msg, Events, Props>) => UI
readonly update: (model: Model, msg: Msg, $: Update<Model, Msg, Events, Props, SpecOf<S, M>>) => U
readonly update: (model: Model, msg: Msg, $: Update<Model, Msg, Events, Props, L>) => U
readonly view: (
model: Model,
h: View.Helper<Msg, Props> & View.Tags<V, Msg> & LoaderHelpers<SpecOf<S, M>>
h: View.Helper<Msg, Props> & View.Tags<V, Msg> & LoaderHelpers<L>
) => UV
readonly subscriptions?:
| ((model: Model, props: Props, loaded: Loaded<SpecOf<S, M>>) => ReadonlyArray<Sub | false | null | undefined>)
| ((
model: Model,
props: Props,
loaded: { readonly [K in keyof NoInfer<L>]: LoadedOf<NoInfer<L>[K]> }
) => ReadonlyArray<Sub | false | null | undefined>)
| undefined
readonly head?:
| ((
model: Model,
loaded: { readonly [K in keyof NoInfer<L>]: LoadedOf<NoInfer<L>[K]> }
) => ReadonlyArray<Head.Entry>)
| undefined
readonly head?: ((model: Model, loaded: Loaded<SpecOf<S, M>>) => ReadonlyArray<Head.Entry>) | undefined
readonly elements?: View.Vocabulary<V> | undefined
}
): Component<
@@ -968,11 +934,11 @@ export const make = <
| StepRequirements<U>
| View.Requirements<UV>
| Subscription.Requirements<Sub>
| LoaderServices<SpecOf<S, M>>,
| LoaderServices<L>,
Command.FrameworkService
>,
V,
SpecOf<S, M>
L
> => {
const bound = loaders.bind(options.name, options.loaders)
const open = (model: unknown, props: unknown, slots: Slots | undefined): any =>
+6 -30
View File
@@ -16,7 +16,6 @@
* @stability experimental
* @since 4.1.5
*/
import type * as Cause from "../Cause.ts"
import type * as Context from "../Context.ts"
import type * as Duration from "../Duration.ts"
import type * as Effect from "../Effect.ts"
@@ -33,25 +32,6 @@ import * as runtime from "./internal/runtime.ts"
import * as services from "./internal/services.ts"
import type * as View from "./View.ts"
/**
* An element's handlers, by event name, as the view declared them.
*
* @stability experimental
* @category models
* @since 4.1.5
*/
export type Handlers = Readonly<Record<string, View.Handler<unknown, any>>>
/**
* An element's event options, by event name, as the view declared them with
* its handlers.
*
* @stability experimental
* @category models
* @since 4.1.5
*/
export type EventOptions = Readonly<Record<string, View.EventOptions>>
/**
* How a host reports an event: the event's name, the handler it found on the
* innermost element with one, and the payload it built.
@@ -119,7 +99,12 @@ export interface Host<Node> {
remove(node: Node): void
parentOf(node: Node): Node | undefined
nextOf(node: Node): Node | undefined
setEvents(node: Node, handlers: Handlers, dispatch: Dispatch, options: EventOptions): void
setEvents(
node: Node,
handlers: Readonly<Record<string, View.Handler<unknown, any>>>,
dispatch: Dispatch,
options: Readonly<Record<string, View.EventOptions>>
): void
readonly elements: ReadonlyArray<string> | "any"
readonly controlled: ReadonlySet<string>
readonly runsMounts: boolean
@@ -547,12 +532,3 @@ export const prerender: <Name extends string, Props, Model, Msg, Events, R, V ex
elements: options?.elements ?? "any",
static: options?.static
})
/**
* A failure as `mount`'s `fallback` and a slot's `onFailure` see it.
*
* @stability experimental
* @category models
* @since 4.1.5
*/
export type Failure = AsyncResult.Failure<never, unknown> & { readonly cause: Cause.Cause<unknown> }
+14 -27
View File
@@ -157,37 +157,17 @@ export type MakeField<S extends Schema.Constraint> = S extends {
: S
/**
* The fields of a params or query Struct, each as `MakeField` gives it.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type MakeFields<Fields extends Schema.Struct.Fields> = { readonly [K in keyof Fields]: MakeField<Fields[K]> }
/**
* A params or query Struct, which `make` fills in, defaults included, when
* no field needs a value.
* A params or query Struct, each field as `MakeField` gives it, which `make`
* fills in, defaults included, when no field needs a value.
*
* @stability experimental
* @category utility types
* @since 4.1.5
*/
export type FieldsSchema<Fields extends Schema.Struct.Fields> = {} extends
Schema.Struct<MakeFields<Fields>>["~type.make.in"] ? Schema.withConstructorDefault<Schema.Struct<MakeFields<Fields>>>
: Schema.Struct<MakeFields<Fields>>
/**
* The Schema of one route's values in a union.
*
* @stability experimental
* @category models
* @since 4.1.5
*/
export type Case<Tag extends string, R> = Schema.TaggedStruct<Tag, {
readonly params: FieldsSchema<ParamFields<R>>
readonly query: FieldsSchema<QueryFields<R>>
}>
Schema.Struct<{ readonly [K in keyof Fields]: MakeField<Fields[K]> }>["~type.make.in"]
? Schema.withConstructorDefault<Schema.Struct<{ readonly [K in keyof Fields]: MakeField<Fields[K]> }>>
: Schema.Struct<{ readonly [K in keyof Fields]: MakeField<Fields[K]> }>
/**
* A redirect: a template whose raw params and query map to a route value.
@@ -240,8 +220,15 @@ export interface Resolved<A> {
* @category models
* @since 4.1.5
*/
export interface Union<Routes extends Record<string, Any>>
extends Schema.TaggedUnion<{ readonly [K in keyof Routes & string]: Case<K, Routes[K]> }>
export interface Union<Routes extends Record<string, Any>> extends
Schema.TaggedUnion<
{
readonly [K in keyof Routes & string]: Schema.TaggedStruct<K, {
readonly params: FieldsSchema<ParamFields<Routes[K]>>
readonly query: FieldsSchema<QueryFields<Routes[K]>>
}>
}
>
{
/** The route definitions, by tag. */
readonly routes: Routes
+9 -5
View File
@@ -295,8 +295,10 @@ export class Replace extends Command.Service<Replace>()(
* @category commands
* @since 4.1.5
*/
export const push = <U extends Routes>(_routes: U, route: U["Type"]): Command.Effectful<Outcome, Push> =>
Push.make({ route })
export const push = <U extends Routes>(
_routes: U,
route: U["Type"]
): Command.Issued<Outcome, Push, Outcome, "Effect"> => Push.make({ route })
/**
* Replaces the current history entry with a route value of the given union.
@@ -312,8 +314,10 @@ export const push = <U extends Routes>(_routes: U, route: U["Type"]): Command.Ef
* @category commands
* @since 4.1.5
*/
export const replace = <U extends Routes>(_routes: U, route: U["Type"]): Command.Effectful<Outcome, Replace> =>
Replace.make({ route })
export const replace = <U extends Routes>(
_routes: U,
route: U["Type"]
): Command.Issued<Outcome, Replace, Outcome, "Effect"> => Replace.make({ route })
/** A query patch: the args Schema of `PatchQuery`. The log encodes it structurally. */
const QueryPatchValue = Schema.declare(
@@ -411,7 +415,7 @@ export const patchQuery = <U extends Routes, R extends U["Type"]>(
readonly history?: "push" | "replace" | undefined
readonly scroll?: boolean | undefined
} | undefined
): Command.Effectful<PatchOutcome, PatchQuery> =>
): Command.Issued<PatchOutcome, PatchQuery, PatchOutcome, "Effect"> =>
PatchQuery.make({
route,
patch: patch as Readonly<Record<string, unknown>>,
+9 -24
View File
@@ -175,7 +175,9 @@ export interface Child<out Msg, out R = never> {
readonly props: unknown
readonly onEmit: (events: any) => Msg | undefined
/** What the slot shows while its child can't be shown. Required for a feature child. */
readonly fallback: ((result: Child.Fallback) => Content<Msg, any>) | undefined
readonly fallback:
| ((result: AsyncResult.Initial<never, unknown> | AsyncResult.Failure<never, unknown>) => Content<Msg, any>)
| undefined
/** Also tells the parent that the child failed. */
readonly onFailure: ((failure: AsyncResult.Failure<never, unknown>) => Msg | undefined) | undefined
/** Phantom: the child's requirements surface in its parent's. */
@@ -189,15 +191,6 @@ export interface Child<out Msg, out R = never> {
* @since 4.1.5
*/
export declare namespace Child {
/**
* What a slot's `fallback` receives: the child's service is still building,
* or the child failed.
*
* @category models
* @since 4.1.5
*/
export type Fallback = AsyncResult.Initial<never, unknown> | AsyncResult.Failure<never, unknown>
/**
* The options of `h.child`. `props` may be left out when the component takes
* none.
@@ -352,18 +345,6 @@ export const build = <Msg, R, const C extends ReadonlyArray<Input<Msg>>>(
children: inputs.length === 0 ? [] : children(inputs)
})
/**
* The fields an element builder holds, which `build` copies onto the element.
*
* @stability experimental
* @category models
* @since 4.1.5
*/
export type BuilderFields = Pick<
Element<unknown>,
"elementKey" | "attrs" | "props" | "handlers" | "eventOptions" | "refKey" | "mount"
>
/**
* Copies a builder with some of its fields replaced, keeping its class. Every
* chain method is written with it, so a builder stays a value.
@@ -374,7 +355,9 @@ export type BuilderFields = Pick<
*/
export const withFields = <B extends ElementBuilder<any, any, any, any>>(
builder: B,
fields: Partial<BuilderFields>
fields: Partial<
Pick<Element<unknown>, "elementKey" | "attrs" | "props" | "handlers" | "eventOptions" | "refKey" | "mount">
>
): B => Object.assign(Object.create(Object.getPrototypeOf(builder)), builder, fields)
/**
@@ -794,7 +777,9 @@ export interface Helper<Msg, Props> {
service: Feature.Service<Self, Props, Events>,
options: Child.Options<Props, Events, Msg> & {
/** Required: the service may be building (`Initial`) or failed (`Failure`). */
readonly fallback: (result: Child.Fallback) => Content<Msg, RF>
readonly fallback: (
result: AsyncResult.Initial<never, unknown> | AsyncResult.Failure<never, unknown>
) => Content<Msg, RF>
}
): Child<Msg, Self | NoInfer<RF>>
/** A component by value. Its requirements surface in the parent's. */
+2 -2
View File
@@ -168,9 +168,9 @@ const controlled: ReadonlySet<string> = new Set(["value", "checked", "selected",
const emptyValue = (name: string): unknown => name === "value" ? "" : false
interface Bound {
readonly handlers: Renderer.Handlers
readonly handlers: Readonly<Record<string, View.Handler<unknown, any>>>
readonly dispatch: Renderer.Dispatch
readonly options: Renderer.EventOptions
readonly options: Readonly<Record<string, View.EventOptions>>
}
const modifiers = (event: Event) => {
+5 -4
View File
@@ -1324,7 +1324,7 @@ export const focus = <N extends HTMLElement | SVGElement, Msg>(
ref: Renderer.Ref<N>,
f: (result: Found) => Msg,
options?: { readonly preventScroll?: boolean | undefined }
): Command.Mapped<Command.Effectful<Found>, Msg> =>
): Command.Mapped<Command.Issued<Found, never, Found, "Effect">, Msg> =>
Command.map(Focus(options === undefined ? { ref } : { ref, options }), f)
/**
@@ -1337,7 +1337,7 @@ export const focus = <N extends HTMLElement | SVGElement, Msg>(
export const blur = <N extends HTMLElement | SVGElement, Msg>(
ref: Renderer.Ref<N>,
f: (result: Found) => Msg
): Command.Mapped<Command.Effectful<Found>, Msg> => Command.map(Blur({ ref }), f)
): Command.Mapped<Command.Issued<Found, never, Found, "Effect">, Msg> => Command.map(Blur({ ref }), f)
/**
* Scrolls the element `ref` names into view, and sends `f`'s message.
@@ -1350,7 +1350,7 @@ export const scrollIntoView = <N extends globalThis.Element, Msg>(
ref: Renderer.Ref<N>,
f: (result: Found) => Msg,
options?: ScrollOptions
): Command.Mapped<Command.Effectful<Found>, Msg> =>
): Command.Mapped<Command.Issued<Found, never, Found, "Effect">, Msg> =>
Command.map(ScrollIntoView(options === undefined ? { ref } : { ref, options }), f)
/**
@@ -1364,4 +1364,5 @@ export const scrollIntoView = <N extends globalThis.Element, Msg>(
export const measure = <N extends globalThis.Element, Msg>(
ref: Renderer.Ref<N>,
f: (rect: Option.Option<Rect>) => Msg
): Command.Mapped<Command.Effectful<Option.Option<Rect>>, Msg> => Command.map(Measure({ ref }), f)
): Command.Mapped<Command.Issued<Option.Option<Rect>, never, Option.Option<Rect>, "Effect">, Msg> =>
Command.map(Measure({ ref }), f)
+2 -2
View File
@@ -99,7 +99,7 @@ const failEnv = (env: Env, cause: Cause.Cause<unknown>) => {
for (const waiter of env.waiters.splice(0)) waiter.failed?.(cause)
}
const memoMapOf = (env: Env): Layer.MemoMap => env.memoMap ??= Layer.CurrentMemoMap.forkOrCreate(env.ctx!)
const unavailable = (env: Env): View.Child.Fallback =>
const unavailable = (env: Env): AsyncResult.Initial<never, unknown> | AsyncResult.Failure<never, unknown> =>
env.failure !== undefined ? AsyncResult.failure(env.failure) : AsyncResult.initial(true)
// ---------------------------------------------------------------------------
@@ -141,7 +141,7 @@ interface RSlot {
// ---------------------------------------------------------------------------
interface Run {
readonly command: Command.Effectful<any, any, never> | Command.Streaming<any, any, never>
readonly command: Command.Issued<any, any, never, "Effect"> | Command.Issued<any, any, never, "Stream">
readonly issued: MessageLog.Issued
/** The run at the cache, begun at issue. `undefined` for a `Command.make` Command. */
readonly handle: Loader.RunHandle | undefined
+35 -35
View File
@@ -90,7 +90,7 @@ import * as Query from "./Query.ts"
* @since 4.1.5
*/
export interface Pending<Msg> {
readonly command: Command.Effectful<Msg, any, never> | Command.Streaming<Msg, any, never>
readonly command: Command.Issued<Msg, any, never, "Effect"> | Command.Issued<Msg, any, never, "Stream">
readonly status: "running" | "queued" | "awaiting"
/** On an awaiting run: the message it delivers when its wait ends. */
readonly message?: Msg | undefined
@@ -144,9 +144,11 @@ export interface Story<Props, Model, Msg, Events, Loaded = { readonly [name: str
* Commands interrupted by `switch`, by an interrupt Command, or by `given`.
* An awaiting run that is cut delivers its message instead, and isn't here.
*/
readonly interrupted: ReadonlyArray<Command.Effectful<Msg, any, never> | Command.Streaming<Msg, any, never>>
readonly interrupted: ReadonlyArray<
Command.Issued<Msg, any, never, "Effect"> | Command.Issued<Msg, any, never, "Stream">
>
/** Commands ignored by `mode: "drop"`. */
readonly dropped: ReadonlyArray<Command.Effectful<Msg, any, never> | Command.Streaming<Msg, any, never>>
readonly dropped: ReadonlyArray<Command.Issued<Msg, any, never, "Effect"> | Command.Issued<Msg, any, never, "Stream">>
/** The list loaders with a load more `update` issued and no step has settled yet. */
readonly loadingMore: ReadonlyArray<string>
/**
@@ -199,6 +201,9 @@ export interface LoaderInfo {
readonly args: unknown
}
// The read of a loader entry, for the steps that name a loader.
type ReadOf<D> = D extends Component.Load<infer R> ? R : D extends Component.LoadMany<infer R> ? R : never
/**
* One key of a `loadMany` loader for `loadedMany`: its args and a Success
* value or a typed failure.
@@ -220,19 +225,6 @@ export type KeyedLoad<R extends Loader.Read.Any> =
readonly waiting?: boolean | undefined
}
/**
* Loaded results for `given`: per loader, the Success value its slot
* starts with, or the entries of a `loadMany` loader.
*
* @stability experimental
* @category models
* @since 4.1.5
*/
export type GivenLoaded<L> = {
readonly [K in keyof L]?: L[K] extends Component.LoadMany<infer R> ? ReadonlyArray<KeyedLoad<R>>
: Loader.Read.Success<Component.ReadOf<L[K]>>
}
/**
* A pending Command's definition, or an issued Command to also match the
* arguments.
@@ -241,7 +233,10 @@ export type GivenLoaded<L> = {
* @category models
* @since 4.1.5
*/
export type Target = Command.Definition.Any | Command.Effectful<any, any, never> | Command.Streaming<any, any, never>
export type Target =
| Command.Definition.Any
| Command.Issued<any, any, never, "Effect">
| Command.Issued<any, any, never, "Stream">
/**
* A stream Command's definition, or an issued stream Command: what `next` and
@@ -251,7 +246,7 @@ export type Target = Command.Definition.Any | Command.Effectful<any, any, never>
* @category models
* @since 4.1.5
*/
export type StreamTarget = Command.Definition<any, any, true, any, any> | Command.Streaming<any, any, never>
export type StreamTarget = Command.Definition<any, any, true, any, any> | Command.Issued<any, any, never, "Stream">
// A component with no messages has `Msg = never`, and its `update` can't take `any`, so it needs its own member.
type AnyComponent =
@@ -302,7 +297,7 @@ export interface Steps<C extends AnyComponent> extends Pipeable {
Component.Model<C>,
Component.Message<C>,
Component.Events<C>,
Component.Loaded<Component.Loaders<C>>
{ readonly [K in keyof Component.Loaders<C>]: Component.LoadedOf<Component.Loaders<C>[K]> }
>
/**
@@ -327,7 +322,11 @@ export interface Steps<C extends AnyComponent> extends Pipeable {
*/
given(
model: Component.Model<C> | ((model: Component.Model<C>) => Component.Model<C>),
loaded?: GivenLoaded<Component.Loaders<C>>
loaded?: {
readonly [K in keyof Component.Loaders<C>]?: Component.Loaders<C>[K] extends Component.LoadMany<infer R>
? ReadonlyArray<KeyedLoad<R>>
: Loader.Read.Success<ReadOf<Component.Loaders<C>[K]>>
}
): this
/**
* Changes the props. A props change never reaches `update`: it re-renders the
@@ -413,7 +412,7 @@ export interface Steps<C extends AnyComponent> extends Pipeable {
*/
loaded<N extends Component.SingleNames<Component.Loaders<C>>>(
name: N,
value: Loader.Read.Success<Component.ReadOf<Component.Loaders<C>[N]>>,
value: Loader.Read.Success<ReadOf<Component.Loaders<C>[N]>>,
options?: { readonly waiting?: boolean | undefined; readonly patched?: boolean | undefined }
): this
/**
@@ -422,8 +421,8 @@ export interface Steps<C extends AnyComponent> extends Pipeable {
*/
loaded<N extends Component.KeyedNames<Component.Loaders<C>>>(
name: N,
args: Loader.Read.Args<Component.ReadOf<Component.Loaders<C>[N]>>,
value: Loader.Read.Success<Component.ReadOf<Component.Loaders<C>[N]>>,
args: Loader.Read.Args<ReadOf<Component.Loaders<C>[N]>>,
value: Loader.Read.Success<ReadOf<Component.Loaders<C>[N]>>,
options?: { readonly waiting?: boolean | undefined; readonly patched?: boolean | undefined }
): this
/**
@@ -434,14 +433,14 @@ export interface Steps<C extends AnyComponent> extends Pipeable {
*/
loadFailed<N extends Component.SingleNames<Component.Loaders<C>>>(
name: N,
error: Loader.Read.Error<Component.ReadOf<Component.Loaders<C>[N]>>,
error: Loader.Read.Error<ReadOf<Component.Loaders<C>[N]>>,
options?: { readonly waiting?: boolean | undefined }
): this
/** Loads one key of a `loadMany` loader with a typed failure, as `loadedMany` does with one entry. */
loadFailed<N extends Component.KeyedNames<Component.Loaders<C>>>(
name: N,
args: Loader.Read.Args<Component.ReadOf<Component.Loaders<C>[N]>>,
error: Loader.Read.Error<Component.ReadOf<Component.Loaders<C>[N]>>,
args: Loader.Read.Args<ReadOf<Component.Loaders<C>[N]>>,
error: Loader.Read.Error<ReadOf<Component.Loaders<C>[N]>>,
options?: { readonly waiting?: boolean | undefined }
): this
/**
@@ -451,7 +450,7 @@ export interface Steps<C extends AnyComponent> extends Pipeable {
*/
loadedMore<N extends Component.ListNames<Component.Loaders<C>>>(
name: N,
page: Loader.ListRead.Page<Component.ReadOf<Component.Loaders<C>[N]>>
page: Loader.ListRead.Page<ReadOf<Component.Loaders<C>[N]>>
): this
/**
* Settles a list loader's pending load more with a failure: the pages stay,
@@ -460,7 +459,7 @@ export interface Steps<C extends AnyComponent> extends Pipeable {
*/
loadMoreFailed<N extends Component.ListNames<Component.Loaders<C>>>(
name: N,
error: Loader.Read.Error<Component.ReadOf<Component.Loaders<C>[N]>>
error: Loader.Read.Error<ReadOf<Component.Loaders<C>[N]>>
): this
/**
* Loads several keys of a `loadMany` loader in one write, as the runtime
@@ -470,7 +469,7 @@ export interface Steps<C extends AnyComponent> extends Pipeable {
*/
loadedMany<N extends Component.KeyedNames<Component.Loaders<C>>>(
name: N,
entries: ReadonlyArray<KeyedLoad<Component.ReadOf<Component.Loaders<C>[N]>>>
entries: ReadonlyArray<KeyedLoad<ReadOf<Component.Loaders<C>[N]>>>
): this
/** Checks the Model. `f` throws to fail the test. */
@@ -1132,7 +1131,7 @@ function* currentEntries(
*/
const awaitedLoaders = (
story: Story<any, any, any, any>,
command: Command.Effectful<any, any, never> | Command.Streaming<any, any, never>,
command: Command.Issued<any, any, never, "Effect"> | Command.Issued<any, any, never, "Stream">,
result: unknown
): ReadonlyArray<AwaitedLoader> => {
const budget = command.afterRefetch
@@ -1163,7 +1162,7 @@ const livePatches = new WeakMap<Pending<any>, ReadonlyArray<{ readonly name: str
/** The component's own loaders, at their current args, that `command`'s patches register on. */
const registeredPatches = (
story: Story<any, any, any, any>,
command: Command.Effectful<any, any, never> | Command.Streaming<any, any, never>
command: Command.Issued<any, any, never, "Effect"> | Command.Issued<any, any, never, "Stream">
): ReadonlyArray<{ readonly name: string; readonly argsKey: string }> => {
if (command.optimistic.length === 0) return []
const out: Array<{ readonly name: string; readonly argsKey: string }> = []
@@ -1198,8 +1197,9 @@ const checkUnpatched = (story: Story<any, any, any, any>, step: string, name: st
}
}
const describe = (command: Command.Effectful<any, any, never> | Command.Streaming<any, any, never>): string =>
`${command.name}(${JSON.stringify(MessageLog.encodeArgs(command.argsSchema, command.args))})`
const describe = (
command: Command.Issued<any, any, never, "Effect"> | Command.Issued<any, any, never, "Stream">
): string => `${command.name}(${JSON.stringify(MessageLog.encodeArgs(command.argsSchema, command.args))})`
const describePending = (pending: ReadonlyArray<Pending<any>>): string =>
pending.length === 0 ?
@@ -1584,7 +1584,7 @@ const findChild = <Msg>(view: View.Node<Msg, any>, key: string, step: string): V
export const fallback = <Msg>(
view: View.Node<Msg, any>,
key: string,
result: View.Child.Fallback
result: AsyncResult.Initial<never, unknown> | AsyncResult.Failure<never, unknown>
): View.Node<Msg, any> | undefined => {
const fallback = findChild(view, key, "fallback").fallback
return fallback === undefined ? undefined : View.toNode(fallback(result))
@@ -1926,6 +1926,6 @@ export const fromLog: <C extends AnyComponent>(
Component.Model<C>,
Component.Message<C>,
Component.Events<C>,
Component.Loaded<Component.Loaders<C>>,
{ readonly [K in keyof Component.Loaders<C>]: Component.LoadedOf<Component.Loaders<C>[K]> },
Component.Props<C>
> = replayLog as any
+2 -2
View File
@@ -90,8 +90,8 @@ export interface TestElement extends Query.Firable {
readonly props: Record<string, unknown>
readonly children: Array<TestNode>
parent: TestElement | undefined
handlers: Renderer.Handlers
eventOptions: Renderer.EventOptions
handlers: Readonly<Record<string, View.Handler<unknown, any>>>
eventOptions: Readonly<Record<string, View.EventOptions>>
dispatch: Renderer.Dispatch | undefined
}
+1 -1
View File
@@ -256,7 +256,7 @@ describe("Command", () => {
const queueing = Command.make("Q", { args: { key: Schema.String }, mode: "queue", group: ["key"] }, done)
const q = (key: string) => queueing({ key })
const entry = (
command: Command.Effectful<any, any>,
command: Command.Issued<any, any, any, "Effect">,
status: "running" | "queued" = "running"
): schedule.Entry<string> => ({
name: command.name,
@@ -771,7 +771,7 @@ describe("BrowserHost", { concurrent: false }, () => {
return Effect.acquireRelease(Effect.succeed({ host, dispatch }), () => Effect.sync(() => host.dispose()))
}
/** The options `onDrop` stores, for a target bound by hand. */
const accepting = (...accepts: ReadonlyArray<string>): Renderer.EventOptions => {
const accepting = (...accepts: ReadonlyArray<string>): Readonly<Record<string, View.EventOptions>> => {
const drop: Html.DropTargetOptions = { accepts, preventDefault: "always" }
return { drop }
}
+31 -19
View File
@@ -44,8 +44,12 @@ describe("Command", () => {
describe("map", () => {
it("keeps the kind and the source result", () => {
const toMessage = (text: string) => Message.make({ _tag: "Got", n: text.length })
expect(Fx().pipe(Command.map(toMessage))).type.toBe<Command.Effectful<typeof Message.Type, never, string>>()
expect(St().pipe(Command.map(toMessage))).type.toBe<Command.Streaming<typeof Message.Type, never, string>>()
expect(Fx().pipe(Command.map(toMessage))).type.toBe<
Command.Issued<typeof Message.Type, never, string, "Effect">
>()
expect(St().pipe(Command.map(toMessage))).type.toBe<
Command.Issued<typeof Message.Type, never, string, "Stream">
>()
expect(Command.map(Command.interrupt(Fx), toMessage)).type.toBe<Command.Interrupt>()
})
@@ -53,8 +57,8 @@ describe("Command", () => {
const input = condition ? Fx() : St()
const mapped = input.pipe(Command.map((text) => Message.make({ _tag: "Got", n: text.length })))
expect(mapped).type.toBe<
| Command.Effectful<typeof Message.Type, never, string>
| Command.Streaming<typeof Message.Type, never, string>
| Command.Issued<typeof Message.Type, never, string, "Effect">
| Command.Issued<typeof Message.Type, never, string, "Stream">
>()
expect($.run).type.toBeCallableWith(mapped)
expect($.run).type.toBeCallableWith(Command.map(input, (text) => Message.make({ _tag: "Got", n: text.length })))
@@ -66,22 +70,27 @@ describe("Command", () => {
Command.map((a) => a.length),
Command.map((n) => Message.make({ _tag: "Got", n }))
)
expect(chained).type.toBe<Command.Effectful<typeof Message.Type, SA, string>>()
expect(chained).type.toBe<Command.Issued<typeof Message.Type, SA, string, "Effect">>()
const stream = SB.make().pipe(
Command.map((n) => n + 1),
Command.map((n) => Message.make({ _tag: "Got", n }))
)
expect(stream).type.toBe<Command.Streaming<typeof Message.Type, SB, number>>()
expect(stream).type.toBe<Command.Issued<typeof Message.Type, SB, number, "Stream">>()
})
it("data-first maps keep each branch's source and requirements across a mixed union", () => {
const input = condition ? Command.map(SA.make(), (a) => a.length) : SB.make()
expect(input).type.toBe<Command.Effectful<number, SA, string> | Command.Streaming<number, SB, number>>()
expect(input).type.toBe<
Command.Issued<number, SA, string, "Effect"> | Command.Issued<number, SB, number, "Stream">
>()
const once = Command.map(input, (n) => n + 1)
expect(once).type.toBe<Command.Effectful<number, SA, string> | Command.Streaming<number, SB, number>>()
expect(once).type.toBe<
Command.Issued<number, SA, string, "Effect"> | Command.Issued<number, SB, number, "Stream">
>()
const twice = Command.map(once, (n) => Message.make({ _tag: "Got", n }))
expect(twice).type.toBe<
Command.Effectful<typeof Message.Type, SA, string> | Command.Streaming<typeof Message.Type, SB, number>
| Command.Issued<typeof Message.Type, SA, string, "Effect">
| Command.Issued<typeof Message.Type, SB, number, "Stream">
>()
expect($.run).type.toBeCallableWith(twice)
// The pipeable form infers one source for its input, so a mixed-source union
@@ -93,18 +102,19 @@ describe("Command", () => {
describe("as", () => {
it("preserves kind, source and requirements in both forms", () => {
const message = Message.make({ _tag: "Got", n: 1 })
expect(SA.make().pipe(Command.as(message))).type.toBe<Command.Effectful<typeof Message.Type, SA, string>>()
expect(Command.as(SB.make(), message)).type.toBe<Command.Streaming<typeof Message.Type, SB, number>>()
expect(SA.make().pipe(Command.as(message))).type.toBe<Command.Issued<typeof Message.Type, SA, string, "Effect">>()
expect(Command.as(SB.make(), message)).type.toBe<Command.Issued<typeof Message.Type, SB, number, "Stream">>()
expect(Command.as(Command.interrupt(Fx), message)).type.toBe<Command.Interrupt>()
const input = condition ? SA.make() : SB.make()
expect(Command.as(input, message)).type.toBe<
Command.Effectful<typeof Message.Type, SA, string> | Command.Streaming<typeof Message.Type, SB, number>
| Command.Issued<typeof Message.Type, SA, string, "Effect">
| Command.Issued<typeof Message.Type, SB, number, "Stream">
>()
const matched = Save.make({ id: "t1", title: "" }).pipe(
Command.match({ onSuccess: () => 1, onFailure: () => 0 }),
Command.as(message)
)
expect(matched).type.toBe<Command.Effectful<typeof Message.Type, Save, string, SaveFailed>>()
expect(matched).type.toBe<Command.Issued<typeof Message.Type, Save, string, "Effect", SaveFailed>>()
expect(Command.as).type.not.toBeCallableWith(Save.make({ id: "t1", title: "" }), message)
expect(Command.interrupt(Fx).pipe).type.not.toBeCallableWith(Command.as(message))
})
@@ -210,7 +220,7 @@ describe("Command", () => {
})
it("maps both channels, keeping the source result and failure", () => {
expect(matched).type.toBe<Command.Effectful<typeof Message.Type, Save, string, SaveFailed>>()
expect(matched).type.toBe<Command.Issued<typeof Message.Type, Save, string, "Effect", SaveFailed>>()
expect($.run).type.toBeCallableWith(matched)
expect<Command.Failure<typeof matched>>().type.toBe<SaveFailed>()
})
@@ -233,12 +243,14 @@ describe("Command", () => {
Command.afterRefetch("Infinity"),
Command.match({ onSuccess: (title) => title.length, onFailure: (error) => error.reason.length })
)
expect(matched).type.toBe<Command.Effectful<number, Save, string, SaveFailed>>()
expect(matched.pipe(Command.afterRefetch(5))).type.toBe<Command.Effectful<number, Save, string, SaveFailed>>()
expect(SA.make().pipe(Command.map((a) => a.length), Command.afterRefetch("1 second"))).type.toBe<
Command.Effectful<number, SA, string>
expect(matched).type.toBe<Command.Issued<number, Save, string, "Effect", SaveFailed>>()
expect(matched.pipe(Command.afterRefetch(5))).type.toBe<
Command.Issued<number, Save, string, "Effect", SaveFailed>
>()
expect(Command.afterRefetch(SA.make(), "1 second")).type.toBe<Command.Effectful<string, SA, string>>()
expect(SA.make().pipe(Command.map((a) => a.length), Command.afterRefetch("1 second"))).type.toBe<
Command.Issued<number, SA, string, "Effect">
>()
expect(Command.afterRefetch(SA.make(), "1 second")).type.toBe<Command.Issued<string, SA, string, "Effect">>()
})
it("rejects a Stream Command and a Command.make Command", () => {
+2 -2
View File
@@ -110,7 +110,7 @@ describe("Component", () => {
{ args: {} },
() => Effect.map(Scope.Scope, () => Message.make({ _tag: "Done" }))
)
expect(UsesScope()).type.toBe<Command.Effectful<typeof Message.Type, never>>()
expect(UsesScope()).type.toBe<Command.Issued<typeof Message.Type, never, typeof Message.Type, "Effect">>()
const C = Component.make({
name: "C",
model: Schema.Struct({}),
@@ -141,7 +141,7 @@ describe("Component", () => {
describe("Command.Service", () => {
it("types the implementation by the message it returns", () => {
expect(SaveTodo.make({ id: "t1", title: "milk", done: false })).type.toBe<
Command.Effectful<TodoItemMessage, SaveTodo>
Command.Issued<TodoItemMessage, SaveTodo, TodoItemMessage, "Effect">
>()
expect(Layer.succeed(SaveTodo)).type.toBeCallableWith(() =>
Effect.succeed(TodoItemMessage.make({ _tag: "Saved" }))
+28 -20
View File
@@ -103,16 +103,21 @@ describe("Component loaders", () => {
expect<Component.SingleNames<L>>().type.toBe<"user" | "team">()
expect<Component.KeyedNames<L>>().type.toBe<never>()
expect<Component.ListNames<L>>().type.toBe<never>()
expect<Component.ReadOf<L["user"]>>().type.toBe<typeof GetUser>()
expect<Component.Loaded<L>>().type.toBe<{
readonly user: AsyncResult.AsyncResult<typeof User.Type, string>
readonly team: AsyncResult.AsyncResult<typeof Team.Type, never>
expect<L>().type.toBe<
{ readonly user: Component.Load<typeof GetUser>; readonly team: Component.Load<typeof GetTeam> }
>()
expect<Component.LoadedOf<L["user"]>>().type.toBe<AsyncResult.AsyncResult<typeof User.Type, string>>()
expect<Component.LoaderHelpers<L>>().type.toBe<{
readonly loaded: {
readonly user: AsyncResult.AsyncResult<typeof User.Type, string>
readonly team: AsyncResult.AsyncResult<typeof Team.Type, never>
}
readonly previous: {
readonly user: Option.Option<typeof User.Type>
readonly team: Option.Option<typeof Team.Type>
}
readonly patched: { readonly user: boolean; readonly team: boolean }
}>()
expect<Component.Previous<L>>().type.toBe<{
readonly user: Option.Option<typeof User.Type>
readonly team: Option.Option<typeof Team.Type>
}>()
expect<Component.Patched<L>>().type.toBe<{ readonly user: boolean; readonly team: boolean }>()
expect<Component.LoaderServices<L>>().type.toBe<GetUser | GetTeam>()
expect<Component.Requirements<typeof Card>>().type.toBe<GetUser | GetTeam>()
})
@@ -254,11 +259,14 @@ describe("Story loader steps", () => {
Component.Model<typeof Card>,
Component.Message<typeof Card>,
never,
Component.Loaded<Component.Loaders<typeof Card>>
{
readonly user: AsyncResult.AsyncResult<typeof User.Type, string>
readonly team: AsyncResult.AsyncResult<typeof Team.Type, never>
}
>
>()
// `loaded()` is typed as `h.loaded` is.
expect(story.loaded().user).type.toBe<Component.ResultOf<typeof GetUser>>()
expect(story.loaded().user).type.toBe<AsyncResult.AsyncResult<typeof User.Type, string>>()
expect(story.loaded()).type.not.toHaveProperty("n")
})
@@ -276,7 +284,7 @@ describe("Story loader steps", () => {
it("fromLog types the replay's props and loaded results", () => {
const replay = Story.fromLog(Card, [])
expect(replay.props).type.toBe<{ readonly id: string }>()
expect(replay.loaded().user).type.toBe<Component.ResultOf<typeof GetUser>>()
expect(replay.loaded().user).type.toBe<AsyncResult.AsyncResult<typeof User.Type, string>>()
expect(replay.loaded()).type.not.toHaveProperty("n")
})
})
@@ -332,21 +340,21 @@ describe("Keyed loaders", () => {
expect<Component.SingleNames<L>>().type.toBe<never>()
expect<Component.ListNames<L>>().type.toBe<never>()
expect<Component.Requirements<typeof List>>().type.toBe<GetUser>()
expect<Component.Loaded<L>["users"]>().type.toBe<Component.KeyedLoaded<typeof GetUser>>()
expect<Component.Loaded<L>["users"][number]["args"]>().type.toBe<{ readonly id: string }>()
expect<Component.Loaded<L>["users"][number]["result"]>().type.toBe<
expect<Component.LoadedOf<L["users"]>>().type.toBe<Component.KeyedLoaded<typeof GetUser>>()
expect<Component.LoadedOf<L["users"]>[number]["args"]>().type.toBe<{ readonly id: string }>()
expect<Component.LoadedOf<L["users"]>[number]["result"]>().type.toBe<
AsyncResult.AsyncResult<typeof User.Type, string>
>()
expect<ReturnType<Component.Loaded<L>["users"]["get"]>>().type.toBe<
expect<ReturnType<Component.LoadedOf<L["users"]>["get"]>>().type.toBe<
Option.Option<Component.KeyedEntry<typeof GetUser>>
>()
expect<Parameters<Component.Loaded<L>["users"]["get"]>[0]>().type.toBe<{ readonly id: string }>()
expect<Parameters<Component.LoadedOf<L["users"]>["get"]>[0]>().type.toBe<{ readonly id: string }>()
})
it("have no previous or patched view", () => {
type L = Component.Loaders<typeof List>
expect<Component.Previous<L>>().type.toBe<{}>()
expect<Component.Patched<L>>().type.toBe<{}>()
expect<Component.LoaderHelpers<L>["previous"]>().type.toBe<{}>()
expect<Component.LoaderHelpers<L>["patched"]>().type.toBe<{}>()
})
it("a keyed loader's loaded doesn't have its own name", () => {
@@ -424,7 +432,7 @@ describe("Keyed loaders", () => {
update: (model) => model,
view: () => null as never
})
expect<Component.Loaded<Component.Loaders<typeof Keyed>>["counts"]>().type.toBe<
expect<Component.LoadedOf<Component.Loaders<typeof Keyed>["counts"]>>().type.toBe<
Component.KeyedLoaded<typeof GetCount>
>()
})
+1 -1
View File
@@ -21,7 +21,7 @@ describe("Router.patchQuery", () => {
{ readonly q?: string | undefined; readonly page?: number | undefined }
>()
expect(Router.patchQuery(AppRoute, search, { q: "a" })).type.toBe<
Command.Effectful<Router.PatchOutcome, Router.PatchQuery>
Command.Issued<Router.PatchOutcome, Router.PatchQuery, Router.PatchOutcome, "Effect">
>()
expect(Router.patchQuery).type.toBeCallableWith(AppRoute, search, {})
// undefined removes a param, or resets a defaulted one.
+1 -1
View File
@@ -105,7 +105,7 @@ describe("Story", () => {
({ name }) => Effect.succeed(`https://cdn/${name}`)
)
const mapped = UploadFile({ name: "me.png" }).pipe(Command.map((url) => Uploaded.make({ _tag: "Uploaded", url })))
expect(mapped).type.toBe<Command.Effectful<typeof Uploaded.Type, never, string>>()
expect(mapped).type.toBe<Command.Issued<typeof Uploaded.Type, never, string, "Effect">>()
expect(counter.resolve).type.toBeCallableWith(mapped, "https://cdn/me.png")
expect(counter.resolve).type.not.toBeCallableWith(mapped, Uploaded.make({ _tag: "Uploaded", url: "" }))
const Progress = Command.make(