Interface: RouterBridge
API / @xmachines/play-vue-router / RouterBridge
Defined in: play-router/src/types.ts:358
The RouterBridge interface of a runtime infrastructure adapter
The interface defines the connection of the lifecycle between the infrastructure, for example a framework router, and the Actor. The infrastructure builds a “bridge” to the Actor: it observes the signals of the Actor, and it manages its own lifecycle accordingly.
Architectural context: the interface implements Passive Infrastructure (INV-04), because it gives an observation in one direction. The infrastructure connects to observe the signals of the Actor (currentRoute, currentView, and state), and it reflects each change. It makes no decision about the state.
Example
The implementation of a framework router bridge
import type { RouterBridge } from "@xmachines/play-router";import { Signal } from "@xmachines/play-signals";
class MyRouterBridge implements RouterBridge { private watcher: Signal.Watcher | null = null;
async connect(): Promise<void> { // Start the observation of the actor.currentRoute signal this.watcher = new Signal.subtle.Watcher(() => { const route = actor.currentRoute.get(); if (route) router.navigate(route); }); this.watcher.watch(actor.currentRoute); }
async disconnect(): Promise<void> { // Stop the observation, and clean the watchers up this.watcher?.unwatch(actor.currentRoute); this.watcher = null; }}See
Play RFC - invariant INV-04
Methods
connect()
connect(): void | Promise<void>;Defined in: play-router/src/types.ts:375
Connects the router bridge to the Actor
The infrastructure calls it when it must start the observation of the Actor signals, and when it must bring its own state, for example the browser URL, in line with the Actor state.
Returns
void | Promise<void>
The promise that resolves after the connection, or void for a synchronous connection
Example
const bridge: RouterBridge = createBridge(actor, router);await bridge.connect();// The bridge observes the actor.currentRoute signal nowdisconnect()
disconnect(): void | Promise<void>;Defined in: play-router/src/types.ts:391
Disconnects the router bridge from the Actor
The infrastructure calls it when it must stop the observation and free its resources, for example a signal watcher and an event listener.
Returns
void | Promise<void>
The promise that resolves after the disconnection, or void for a synchronous disconnection
Example
await bridge.disconnect();// The bridge stopped its observation, and it freed its resources