move-by-move 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,21 +1,19 @@
1
- export type Immutable<T> = 0 extends 1 & T ? T : T extends readonly (infer E)[] ? readonly Immutable<E>[] : T extends object ? {
2
- readonly [K in keyof T]: Immutable<T[K]>;
3
- } : T;
4
- export type GameAction = {
1
+ type GameAction = {
5
2
  type: string;
6
3
  };
7
- export interface Game<State, Action extends GameAction> {
4
+ interface Game<State, Action extends GameAction> {
8
5
  subscribe(listener: Function): () => void;
9
6
  getState(): State;
10
7
  move(action: Action): void;
11
8
  }
12
- export type RuleIO<State, Action extends GameAction> = [state: State, action: Action, context: Record<string, unknown>];
13
- export type Rule<State, Action extends GameAction> = (input: RuleIO<Immutable<State>, Immutable<Action>>) => RuleIO<State, Action>;
14
- export type Produce = <S>(base: S, recipe: (draft: S) => void) => S;
9
+ type RuleIO<State, Action extends GameAction> = [state: State, action: Action, context: Record<string, unknown>];
10
+ type Rule<State, Action extends GameAction> = (input: RuleIO<State, Action>) => RuleIO<State, Action>;
11
+ type Produce = <S>(base: S, recipe: (draft: S) => void) => S;
15
12
  export declare function createRuleFactory<State, Action extends GameAction>(produce: Produce): {
16
- (recipe: (state: State, action: Immutable<Action>, context: Record<string, unknown>) => void): Rule<State, Action>;
17
- <Type extends Action["type"]>(type: Type, recipe: (state: State, action: Immutable<Extract<Action, {
13
+ (recipe: (state: State, action: Action, context: Record<string, unknown>) => void): Rule<State, Action>;
14
+ <Type extends Action["type"]>(type: Type, recipe: (state: State, action: Extract<Action, {
18
15
  type: Type;
19
- }>>, context: Record<string, unknown>) => void): Rule<State, Action>;
16
+ }>, context: Record<string, unknown>) => void): Rule<State, Action>;
20
17
  };
21
18
  export default function createGame<State, Action extends GameAction>(rules: Array<Rule<State, Action>>, initialGameState: State): Game<State, Action>;
19
+ export {};
package/lib/index.js CHANGED
@@ -29,7 +29,7 @@ export default function createGame(rules, initialGameState) {
29
29
  return state;
30
30
  };
31
31
  const move = (action) => {
32
- const result = pipe(...rules)([state, action, {}]);
32
+ const result = pipe(...(rules))([state, action, {}]);
33
33
  state = result[0];
34
34
  for (const listener of listeners) {
35
35
  listener();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "move-by-move",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Simple game engine for turn based games",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",