Skip to content

concepts

The headless core

A plain store, events and commands; ports supplied by the host.

The core holds the state of the session, the bet and the round, plays a round's events in order and exposes three things: a readable store, an event bus and a dispatch for commands. It uses no UI framework, no PixiJS and no DOM, so it runs in Node under tests with fake ports and in any browser host.

keystone-core (abridged)
export interface IEngine<TEvent> {
  readonly state: IReadableStore<IEngineState>;   // get() and subscribe()
  readonly events: IEventBus<TEngineEvent<TEvent>>;
  dispatch(command: TEngineCommand): void;
  trigger(action: TInputAction, source: TEngineInputSource): void;
  readonly money: (amountMinor: number) => string;
  destroy(): void;
  // ...
}

Ports

Everything outside the core comes in through ports that the host supplies. keystone-web implements them for browsers; a test supplies fakes.

keystone-core (abridged)
export interface IEnginePorts {
  readonly transport: TFetchFunction;   // the round server API
  readonly storage: { readonly local: IStoragePort; readonly session: IStoragePort };
  readonly scheduler: IScheduler;       // now, setTimeout, clearTimeout
  readonly audioOutput: IAudioOutput;   // the audio graph the director drives
  readonly host: IEngineHost;           // balance display, operator commands and messages
  readonly visibility: { readonly hidden: IReadableStore<boolean> };
  // ...
}

State

The state covers the session (balance, currency, responsible-gaming view), the bet (modes, bet size, buys), the round (phase, round id, running win, speed), autoplay, player settings, effective flags such as turbo or minimum round time, the open dialog, history, rules and whether a spin is allowed now.