@vuecs/navigation
Version:
A package for multi level navigations.
42 lines • 1.89 kB
TypeScript
import type { NavigationRegistryEntry } from './types';
type Occupant = {
token: symbol;
entry: NavigationRegistryEntry;
};
type NavigationRegistryUnregisterFn = () => void;
/**
* Reactive, app-wide navigation registry. `<VCNavItems registry>`
* publishes its resolved output here under a `registry-id`; other navs
* read it reactively + empty-safe via the resolver context's
* `registry(id)`.
*
* The backing map is `shallowReactive`, so membership changes
* (register + the returned unregister closure) are tracked dependencies
* — a consumer reading `get(id)` inside a `computed` / `watchEffect`
* re-runs when the id's occupancy flips.
*/
export declare class NavigationRegistry {
protected map: import("vue").ShallowReactive<Map<string, Occupant>>;
/**
* Stable empty entries handed out for absent ids, memoized per id so
* the SAME reactive handle is returned every call — a consumer
* subscribed to an absent id keeps its dependency and lights up the
* moment an occupant registers.
*/
protected empties: Map<string, NavigationRegistryEntry>;
/**
* Claim `id`. Last-wins: a newer occupant replaces the current one
* (dev warning on collision). Returns a token-guarded unregister
* closure: it releases `id` ONLY if this registration is still the
* occupant. During a route handoff (Vue mounts the new page before
* unmounting the old) the departing nav's closure holds a stale token
* and cannot evict the incoming occupant.
*/
register(id: string, entry: NavigationRegistryEntry): NavigationRegistryUnregisterFn;
/** Reactive, empty-safe read. Never returns `undefined`. */
get<META = any>(id: string): NavigationRegistryEntry<META>;
/** True when an occupant currently holds `id`. */
has(id: string): boolean;
}
export {};
//# sourceMappingURL=module.d.ts.map