Browser History navigator — batteries web shell. Short names ↔ /Nwsl/HttpApi.
export const const history: (
root: RouteGroup
) => Layer.Layer<Navigator>
Browser History navigator — batteries web shell. Short names ↔ /Nwsl/HttpApi.
history = (root: RouteGroup(parameter) root: {
key: string;
members: Record<string, unknown>;
}
root: type RouteGroup = {
readonly key: string;
readonly members: Record<string, unknown>;
}
A group-shaped node the router can walk (Group.Tag or { key, members }).
RouteGroup): import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<class Navigatorclass Navigator {
key: Identifier;
Service: {
root: RouteGroup;
mode: "memory" | "history";
path: ReadonlyArray<string>;
trail: ReadonlyArray<RouteGroup>;
group: RouteGroup;
selected: unknown | null;
view: string | undefined;
open: (member: MemberTag) => void;
openKey: (key: string) => void;
back: () => void;
toRoot: () => void;
openLogs: (tag: LeafTag) => void;
openSchedule: (tag: LeafTag) => void;
subscribe: (listener: () => void) => () => void;
syncFromLocation: () => void;
};
}
Navigator Context service — provide with
memory
/
history
.
Navigator> =>
import LayerLayer.const sync: {
<I, S>(service: Context.Key<I, S>): (
evaluate: LazyArg<S>
) => Layer<I>
<I, S>(
service: Context.Key<I, S>,
evaluate: LazyArg<Types.NoInfer<S>>
): Layer<I>
}
Constructs a layer lazily that provides a single service.
When to use
Use when you need a Layer that provides one service whose value is created
synchronously, but creation should be deferred until the layer is built.
Details
This is a lazy version of succeed where the service value is computed
synchronously only when the layer is built.
Example (Lazily providing a service)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const layer = Layer.sync(Database, () => ({
query: (sql: string) => Effect.succeed(`Query: ${sql}`)
}))
sync(class Navigatorclass Navigator {
key: Identifier;
Service: {
root: RouteGroup;
mode: "memory" | "history";
path: ReadonlyArray<string>;
trail: ReadonlyArray<RouteGroup>;
group: RouteGroup;
selected: unknown | null;
view: string | undefined;
open: (member: MemberTag) => void;
openKey: (key: string) => void;
back: () => void;
toRoot: () => void;
openLogs: (tag: LeafTag) => void;
openSchedule: (tag: LeafTag) => void;
subscribe: (listener: () => void) => () => void;
syncFromLocation: () => void;
};
of: (this: void, self: Service) => Service;
context: (self: Service) => Context.Context<Navigator>;
use: (f: (service: Service) => Effect<A, E, R>) => Effect<A, E, Navigator | R>;
useSync: (f: (service: Service) => A) => Effect<A, never, Navigator>;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Navigator Context service — provide with
memory
/
history
.
Navigator, () => const makeService: (
root: RouteGroup,
mode: "memory" | "history"
) => Service
makeService(root: RouteGroup(parameter) root: {
key: string;
members: Record<string, unknown>;
}
root, "history"));