1 | "use strict";
|
2 | var OpaqueToken = (function () {
|
3 | function OpaqueToken(_desc) {
|
4 | this._desc = _desc;
|
5 | }
|
6 | OpaqueToken.prototype.toString = function () { return "Token " + this._desc; };
|
7 | return OpaqueToken;
|
8 | }());
|
9 | exports.OpaqueToken = OpaqueToken;
|
10 | exports.HMR_STATE = new OpaqueToken('hmrState');
|
11 | var HmrStore = (function () {
|
12 | function HmrStore() {
|
13 | }
|
14 | HmrStore.set = function (prop, value) {
|
15 | HmrStore._state[prop] = value;
|
16 | return HmrStore._state[prop];
|
17 | };
|
18 | HmrStore.get = function (prop) {
|
19 | return HmrStore._state[prop];
|
20 | };
|
21 | HmrStore.select = function (name, getState) {
|
22 | HmrStore._states.push({ name: name, getState: getState });
|
23 | var defaultData = getState();
|
24 | var currentData = HmrStore.get(name);
|
25 | if (defaultData && !currentData) {
|
26 | return HmrStore.set(name, defaultData);
|
27 | }
|
28 | else if (defaultData && currentData) {
|
29 | return HmrStore.set(name, Object.assign({}, defaultData, currentData));
|
30 | }
|
31 | else {
|
32 | return HmrStore.set(name, currentData || defaultData);
|
33 | }
|
34 | };
|
35 | HmrStore.dispose = function () {
|
36 | HmrStore._states = [];
|
37 | HmrStore._state = {};
|
38 | HmrStore._initialValues = {};
|
39 | };
|
40 | HmrStore.getState = function () {
|
41 | var initialState = Object.assign({}, HmrStore._state);
|
42 | return HmrStore._states
|
43 | .reduce(function (memo, item) {
|
44 | memo[item.name] = item.getState();
|
45 | return memo;
|
46 | }, initialState);
|
47 | };
|
48 | HmrStore.toJSON = function () {
|
49 | return HmrStore.getState();
|
50 | };
|
51 | HmrStore.dev = false;
|
52 | HmrStore._state = {};
|
53 | HmrStore._initialValues = {};
|
54 | HmrStore._states = [];
|
55 | return HmrStore;
|
56 | }());
|
57 | exports.HmrStore = HmrStore;
|
58 |
|
\ | No newline at end of file |