Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

createActionDispatch

import { createActionDispatch } from "https://raw.githubusercontent.com/Hatscat/MetavaScript/main/index.ts";

helper to create the dispatch(action) function, in the context of the State Mutator pattern

@example
const state = {
  player: {
    x: "px",
    y: "py",
  },
};

type Action = {
  type: "jump";
} | {
  type: "move";
  payload: {
    direction: "left" | "right";
  };
};

const mutator = (st: typeof state, action: Action): string => {
  switch (action.type) {
    case "jump":
      return decrement(st.player.y);
    case "move":
      return increment(st.player.x);
  }
};

const dispatch = createActionDispatch(state, mutator);

// returns "py--"
dispatch({ type: "jump" });
// returns "px++"
dispatch({ type: "move", payload: { direction: "right" } });
function createActionDispatch<ActionType, State extends {
[key: string]: unknown;
}
, Action extends ActionBase<ActionType>>
(state: State, mutator: (state: State, action: Action) => string): (action: Action) => string;
§
createActionDispatch<ActionType, State extends {
[key: string]: unknown;
}
, Action extends ActionBase<ActionType>>
(state: State, mutator: (state: State, action: Action) => string): (action: Action) => string
[src]

§Type Parameters

§
ActionType
[src]
§
State extends {
[key: string]: unknown;
}
[src]
§
Action extends ActionBase<ActionType>
[src]

§Parameters

§
state: State
[src]
§
mutator: (state: State, action: Action) => string
[src]

§Return Type

§
(action: Action) => string
[src]