1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = queueReducer;
|
7 |
|
8 | var _zSchema = require("z-schema");
|
9 |
|
10 | var _zSchema2 = _interopRequireDefault(_zSchema);
|
11 |
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 |
|
14 | var validator = new _zSchema2.default();
|
15 |
|
16 | function queueReducer(state, action) {
|
17 | if (state.game.queue && state.game.queue.length > 0) {
|
18 | var schema = state.game.queue[0];
|
19 |
|
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 |
|
\ | No newline at end of file |