Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @lauf/store-follow

Lightweight Application State Eventing

codecov

Logo - Image of Runner

Lauf Store Follow

Logo - Diego Naive, Noun Project.

Install

npm install @lauf/store-follow --save

@lauf/store-follow provides simple async monitoring primitives to trigger business logic when application state changes. It builds upon @lauf/store, (a simple substitute for Flux/Redux based on Immer).

To find out more;

Index

Type aliases

Controls

Controls<Selected, Ending>: { exit: (ending: Ending) => ExitStatus; lastSelected: () => Selected | undefined }

A control object for a Follower function to signal exit behaviour, retrieve references.

Type parameters

  • Selected

  • Ending

Type declaration

  • exit: (ending: Ending) => ExitStatus
  • lastSelected: () => Selected | undefined
      • (): Selected | undefined
      • Returns Selected | undefined

ExitStatus

ExitStatus: ["exit"]

A type used as a special return value.

Follower

Follower<Selected, Ending>: (selected: Selected, controlHandle: Controls<Selected, Ending>) => Promise<void | ExitStatus>

Type parameters

  • Selected

  • Ending

Type declaration

    • (selected: Selected, controlHandle: Controls<Selected, Ending>): Promise<void | ExitStatus>
    • A function to notify a series of changing values from a store.

      Parameters

      • selected: Selected
      • controlHandle: Controls<Selected, Ending>

      Returns Promise<void | ExitStatus>

QueueHandler

QueueHandler<Selected, Ending>: (valueQueue: MessageQueue<Selected>, initialValue: Selected) => Promise<Ending>

Type parameters

  • Selected

  • Ending

Type declaration

    • (valueQueue: MessageQueue<Selected>, initialValue: Selected): Promise<Ending>
    • Function to process a queue of values including an initial starting value, leading to a final Ending result.

      Parameters

      Returns Promise<Ending>

Functions

followSelector

  • followSelector<State, Selected, Ending>(store: Store<State>, selector: Selector<State, Selected>, follower: Follower<Selected, Ending>): Promise<Ending>
  • Invokes the follower once with the initial value of selector and again every time store has a changed value of Selector. If follower is async, each invocation will be awaited before the next is called.

    The follower is passed the new value each time, and also a control object which can be used to exit the loop like return control.exit(myValue). If follower doesn't return an exit instruction, its return value is ignored and it will be invoked again on the the next Selector change.

    Type parameters

    • State: object

    • Selected

    • Ending

    Parameters

    • store: Store<State>

      The store to follow

    • selector: Selector<State, Selected>

      The function to extract the selected value

    • follower: Follower<Selected, Ending>

      The callback to handle each changing value

    Returns Promise<Ending>

    Any Ending returned when exiting the loop

withSelectorQueue

  • withSelectorQueue<State, Selected, Ending>(store: Store<State>, selector: Selector<State, Selected>, handleQueue: QueueHandler<Selected, Ending>): Promise<Ending>
  • Configures a MessageQueue that will receive messages with every new value of a Selector against a Store. Passes the queue and the initial value from the Selector to handleQueue then waits for handleQueue to return, after which the queue is unsubscribed.

    Type parameters

    • State: object

    • Selected

    • Ending

    Parameters

    • store: Store<State>

      Store to monitor

    • selector: Selector<State, Selected>

      Function that extracts the selected value

    • handleQueue: QueueHandler<Selected, Ending>

      Function passed the initial selected value and queue

    Returns Promise<Ending>

    the value returned by handleQueue

Generated using TypeDoc