1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 | var state = {
|
5 | __container__: {}
|
6 | };
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | exports.init = function init(config) {
|
21 | state.__container__[config.name] = config.defaultValue;
|
22 | Object.defineProperty(state, config.name, {
|
23 | get: function get() {
|
24 | return state.__container__[config.name];
|
25 | },
|
26 | set: function set(value) {
|
27 | if (config.shouldUpdate)
|
28 | if (
|
29 | config.shouldUpdate(state.__container__[config.name], value) === false
|
30 | )
|
31 | return;
|
32 |
|
33 | config.willUpdate &&
|
34 | config.willUpdate(state.__container__[config.name], value);
|
35 | state.__container__[config.name] = value;
|
36 | config.didUpdate && config.didUpdate(value);
|
37 | }
|
38 | });
|
39 | };
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | exports.state = state;
|