move-by-move 1.0.1 → 1.0.5
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 +8 -8
- package/lib/index.js +6 -5
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export interface GameAction {
|
|
2
2
|
type: string;
|
|
3
3
|
}
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export default createGame
|
|
4
|
+
export interface Game<Type> {
|
|
5
|
+
subscribe(listener: Function): void;
|
|
6
|
+
unsubscribe(listener: Function): void;
|
|
7
|
+
getState(): Type;
|
|
8
|
+
move(action: GameAction): void;
|
|
9
|
+
}
|
|
10
|
+
export declare type RuleIO<Type> = [action: GameAction, state: Type];
|
|
11
|
+
export default function createGame<Type>(rules: Array<(input: RuleIO<Type>) => RuleIO<Type>>, initialGameState: Type): Game<Type>;
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const helpers_1 = require("./helpers");
|
|
4
|
-
|
|
4
|
+
function createGame(rules, initialGameState) {
|
|
5
5
|
let listeners = [];
|
|
6
6
|
let state = initialGameState;
|
|
7
7
|
const subscribe = (listener) => {
|
|
8
8
|
listeners = [...listeners, listener];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
};
|
|
10
|
+
const unsubscribe = (listener) => {
|
|
11
|
+
listeners = listeners.filter(item => item !== listener);
|
|
12
12
|
};
|
|
13
13
|
const getState = () => {
|
|
14
14
|
return state;
|
|
@@ -22,8 +22,9 @@ const createGame = (rules, initialGameState) => {
|
|
|
22
22
|
};
|
|
23
23
|
return {
|
|
24
24
|
subscribe,
|
|
25
|
+
unsubscribe,
|
|
25
26
|
getState,
|
|
26
27
|
move,
|
|
27
28
|
};
|
|
28
|
-
}
|
|
29
|
+
}
|
|
29
30
|
exports.default = createGame;
|