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 +9 -11
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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:
|
|
17
|
-
<Type extends Action["type"]>(type: Type, recipe: (state: State, 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
|
-
}
|
|
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();
|