Skip to content

Abstract Class: RouterBridgeBase

API / @xmachines/play-router / RouterBridgeBase

Defined in: router-bridge-base.ts:99

The abstract base class of every router adapter bridge of @xmachines.

The class implements the RouterBridge protocol, and it holds every part of the bridge logic that the adapters share. A subclass implements the 3 abstract methods that are different in each framework, and it implements nothing more.

Extended by

Implements

Constructors

Constructor

new RouterBridgeBase(actor, routeMap): RouterBridgeBase;

Defined in: router-bridge-base.ts:127

Parameters

ParameterTypeDescription
actorRoutableActorA RoutableActor, with currentRoute, initialRoute, and send.
routeMap{ getPathByStateId: string | null | undefined; getStateIdByPath: string | null | undefined; }The route map of both directions, for the resolution between a stateId and a path. Give getStateIdByPath and getPathByStateId. A framework adapter usually wraps the result of createRouteMap(machine), or an equivalent value. The key of getPathByStateId is the form "#stateId" or the bare form "stateId". The bridge tries both forms. Therefore an implementation of your own, for example a plain test object, handles one form only.
routeMap.getPathByStateId-
routeMap.getStateIdByPath-

Returns

RouterBridgeBase

Methods

connect()

connect(): void;

Defined in: router-bridge-base.ts:158

Connects the router bridge to the Actor.

The method installs the TC39 Signal watcher of the direction from the actor to the router. It then starts the watch of the router changes, which each framework does in its own way.

The order of these steps is part of the contract of the bridge:

  • The constructor seeds lastSyncedPath from actor.currentRoute
  • The method installs the actor watcher before the router subscriptions of the adapter
  • The first synchronization then separates a deep link from a restore, with actor.initialRoute

An adapter that needs a different behavior of the first synchronization overrides getInitialRouterPath(). It does not change the order of the steps of connect().

Returns

void

Implementation of

RouterBridge.connect


disconnect()

disconnect(): void;

Defined in: router-bridge-base.ts:270

Disconnects the router bridge from the Actor.

The method stops the watch of the signal, and it removes the router listener of the framework.

Returns

void

Implementation of

RouterBridge.disconnect