UNPKG

1.79 kBJavaScriptView Raw
1"use strict";
2var hmr_store_1 = require('./hmr-store');
3// noop in parentNode
4// TODO: find a better way to noop
5var _env = typeof process !== 'undefined' &&
6 process &&
7 process.env &&
8 (process.env.ENV ||
9 process.env.NODE_ENV);
10var _dev = ((_env &&
11 typeof _env === 'string' &&
12 (_env.indexOf('dev') > -1)) ||
13 _env === undefined);
14function setDev(newDev) {
15 if (typeof newDev === 'string') {
16 return _dev = (newDev.indexOf('dev') > -1);
17 }
18 else if (typeof newDev === 'boolean') {
19 return _dev = newDev;
20 }
21 throw new Error('Please provide a string or boolean');
22}
23exports.setDev = setDev;
24function HmrState(namespaceOrConfig, config) {
25 function decoratorFactory(target, decoratedPropertyName, descriptor) {
26 if (!_dev) {
27 return descriptor;
28 }
29 var key = namespaceOrConfig || target.constructor.name + '#' + decoratedPropertyName;
30 hmr_store_1.HmrStore.select(key, function () { return hmr_store_1.HmrStore.get(key); });
31 Object.defineProperty(target, decoratedPropertyName, {
32 get: function () { return hmr_store_1.HmrStore.get(key); },
33 set: function (newValue) {
34 var currentValue = hmr_store_1.HmrStore.get(key);
35 if (!currentValue) {
36 hmr_store_1.HmrStore._initialValues[key] = newValue;
37 }
38 else {
39 newValue = Object.assign(newValue, currentValue);
40 }
41 return hmr_store_1.HmrStore.set(key, newValue);
42 },
43 enumerable: true,
44 configurable: true
45 });
46 return descriptor;
47 }
48 return decoratorFactory;
49}
50exports.HmrState = HmrState;
51//# sourceMappingURL=hmr-decorator.js.map
\No newline at end of file