mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
- References are Ref<C> (was Handle<C>), objects ObjectImpl (record.ts is object.ts), ImplementationOf<C> (was
BehaviorOf<C>), ResourceDeclaration (was ResourceSpec); epochs are code versions (codeVersion in Ctx, RootOptions,
Shape, Host, frames and reload reports). Docs say object and reference.
- A remote object's variant is named variant (was kind): factories return { variant }, references expose ref.variant.
- Links announce a protocol version (PROTOCOL_VERSION = 2) in hello; peers of different versions close the link with
reason protocol-version <n> and report it through LinkOptions.onProtocolMismatch.
- ServeOptions.lifetime ("referenced" | "host") replaces eager: a host-lifetime object is local, has an empty input,
exists once per host and lives until the host closes; awaitEager is awaitHostObjects. A reload that makes a type
referenced releases the host's own reference.
30 lines
1 KiB
TypeScript
30 lines
1 KiB
TypeScript
import type { Ctx } from "./types.ts";
|
|
|
|
export interface Registry<V> {
|
|
readonly name: string;
|
|
readonly conflict: "error" | "last";
|
|
/** Type carrier only; never set. */
|
|
readonly value?: V;
|
|
}
|
|
|
|
/** `conflict: "error"` rejects two objects registering one key; `"last"` keeps the later registration. */
|
|
export const defineRegistry = <V>(name: string, options: { conflict?: "error" | "last" } = {}): Registry<V> => ({
|
|
name,
|
|
conflict: options.conflict ?? "error",
|
|
});
|
|
|
|
export type RegistryTable<V> = ReadonlyMap<string, V>;
|
|
|
|
export interface RegistryView<V> {
|
|
/** Table of `ctx.codeVersion`, or of the current code version without ctx. */
|
|
table(ctx?: Ctx): RegistryTable<V>;
|
|
get(key: string, ctx?: Ctx): V | undefined;
|
|
/** Called with the current table immediately and whenever a new table is installed. */
|
|
subscribe(listener: (table: RegistryTable<V>, codeVersion: number) => void): () => void;
|
|
}
|
|
|
|
export interface Registration {
|
|
readonly registry: Registry<unknown>;
|
|
readonly key: string;
|
|
readonly value: unknown;
|
|
}
|