1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.untypeEvent = exports.typeEvent = void 0;
|
7 | var _actions = require("./actions");
|
8 | const typeId = '@@type';
|
9 | const globalStore = {};
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | const typeEvent = (update, store = globalStore, create = _actions.createAction) => {
|
16 | const map = event => {
|
17 | if (!event.type) {
|
18 | return event;
|
19 | }
|
20 | const {
|
21 | type,
|
22 | payload = null
|
23 | } = event;
|
24 | const typed = store[type];
|
25 | if (typed) {
|
26 | return typed.of(payload);
|
27 | }
|
28 | store[type] = create(type);
|
29 | return store[type].of(payload);
|
30 | };
|
31 | return (state, event) => update(state, map(event));
|
32 | };
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | exports.typeEvent = typeEvent;
|
39 | const untypeEvent = update => {
|
40 | const map = event => {
|
41 | if (!event.join || !event[typeId]) {
|
42 | return event;
|
43 | }
|
44 | return {
|
45 | type: event[typeId],
|
46 | payload: event.join()
|
47 | };
|
48 | };
|
49 | return (state, event) => update(state, map(event));
|
50 | };
|
51 | exports.untypeEvent = untypeEvent; |
\ | No newline at end of file |