Class View<S, E>

View is a datatype that represents the event handling algorithm, responsible for translating the events into denormalized state, which is more adequate for querying.

Author

Иван Дугалић / Ivan Dugalic /

Idugalic

Type Parameters

  • S

    State

  • E

    Event

    Example

    const view: View<number, OddNumberEvt> = new View<number, OddNumberEvt>(
    (s, e) => {
    if (e instanceof OddNumberAddedEvt) {
    return s + e.value;
    } else if (e instanceof OddNumberMultiplied) {
    return s * e.value;
    } else {
    const _: never = e;
    console.log('Never just happened in evolve function: ' + _);
    return s;
    }
    },
    0
    );

Implements

Constructors

  • Type Parameters

    • S

    • E

    Parameters

    • evolve: ((s, e) => S)
        • (s, e): S
        • Parameters

          • s: S
          • e: E

          Returns S

    • initialState: S

    Returns View<S, E>

Properties

evolve: ((s, e) => S)

Type declaration

    • (s, e): S
    • Parameters

      • s: S
      • e: E

      Returns S

initialState: S

Methods

  • Combines Views into one bigger View

    Type Parameters

    • S2

    • E2

    Parameters

    Returns View<readonly [S, S2], E | E2>

  • Dimap on S/State parameter

    Type Parameters

    • Sn

      New State

    Parameters

    • fl: ((sn) => S)
        • (sn): S
        • Parameters

          • sn: Sn

          Returns S

    • fr: ((s) => Sn)
        • (s): Sn
        • Parameters

          • s: S

          Returns Sn

    Returns View<Sn, E>

  • Left map on E/Event parameter

    Type Parameters

    • En

      New Event

    Parameters

    • f: ((en) => E)
        • (en): E
        • Parameters

          • en: En

          Returns E

    Returns View<S, En>

Generated using TypeDoc