UNPKG

1.25 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = queueReducer;
7
8var _zSchema = require("z-schema");
9
10var _zSchema2 = _interopRequireDefault(_zSchema);
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14var validator = new _zSchema2.default(); // import Ajv from "ajv";
15// const ajv = new Ajv({ allErrors: true });
16function queueReducer(state, action) {
17 if (state.game.queue && state.game.queue.length > 0) {
18 var schema = state.game.queue[0];
19 // const validate = ajv.compile(schema);
20
21 var valid = validator.validate(action, schema);
22 if (!valid) {
23 throw new Error(JSON.stringify({ action: action, errors: validator.getLastErrors() }, null, 2));
24 }
25 }
26 if (state.game.nextActions) {
27 return Object.assign({}, state, {
28 game: Object.assign({}, state.game, {
29 queue: state.game.nextActions.map(function (action) {
30 return {
31 type: "object",
32 properties: {
33 type: {
34 type: "string",
35 enum: [action.action.type]
36 }
37 }
38 };
39 })
40 })
41 });
42 }
43
44 return state;
45}
46//# sourceMappingURL=queue-reducer.js.map
\No newline at end of file