move-by-move 2.0.0 → 3.0.0
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/helpers.d.ts +1 -1
- package/lib/helpers.js +1 -5
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -6
- package/package.json +11 -3
package/lib/helpers.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const pipe: <T>(...fns: (
|
|
1
|
+
export declare const pipe: <T>(...fns: Array<(arg: T) => T>) => (value: T) => T;
|
package/lib/helpers.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pipe = void 0;
|
|
4
|
-
const pipe = (...fns) => (value) => fns.reduce((acc, fn) => fn(acc), value);
|
|
5
|
-
exports.pipe = pipe;
|
|
1
|
+
export const pipe = (...fns) => (value) => fns.reduce((acc, fn) => fn(acc), value);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type GameAction<Payload = any> = Payload & {
|
|
2
2
|
type: string;
|
|
3
3
|
};
|
|
4
4
|
export interface Game<Type> {
|
|
@@ -6,5 +6,5 @@ export interface Game<Type> {
|
|
|
6
6
|
getState(): Type;
|
|
7
7
|
move(action: GameAction): void;
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export type RuleIO<Type> = [action: GameAction, state: Type];
|
|
10
10
|
export default function createGame<Type>(rules: Array<(input: RuleIO<Type>) => RuleIO<Type>>, initialGameState: Type): Game<Type>;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const helpers_1 = require("./helpers");
|
|
4
|
-
function createGame(rules, initialGameState) {
|
|
1
|
+
import { pipe } from './helpers.js';
|
|
2
|
+
export default function createGame(rules, initialGameState) {
|
|
5
3
|
let listeners = [];
|
|
6
4
|
let state = initialGameState;
|
|
7
5
|
const unsubscribe = (listener) => {
|
|
@@ -15,7 +13,7 @@ function createGame(rules, initialGameState) {
|
|
|
15
13
|
return state;
|
|
16
14
|
};
|
|
17
15
|
const move = (action) => {
|
|
18
|
-
const result =
|
|
16
|
+
const result = pipe(...rules)([action, state]);
|
|
19
17
|
state = result[1];
|
|
20
18
|
for (const listener of listeners) {
|
|
21
19
|
listener();
|
|
@@ -27,4 +25,3 @@ function createGame(rules, initialGameState) {
|
|
|
27
25
|
move,
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
|
-
exports.default = createGame;
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "move-by-move",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Simple game engine for turn based games",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "lib/index.js",
|
|
6
|
-
"
|
|
7
|
+
"module": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"default": "./lib/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"files": [
|
|
8
16
|
"lib"
|
|
9
17
|
],
|
|
@@ -19,6 +27,6 @@
|
|
|
19
27
|
"author": "Andreas Riedmüller",
|
|
20
28
|
"license": "MIT",
|
|
21
29
|
"devDependencies": {
|
|
22
|
-
"typescript": "^
|
|
30
|
+
"typescript": "^6.0.3"
|
|
23
31
|
}
|
|
24
32
|
}
|