reactant-model 0.36.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +102 -1
- package/dist/index.esm.js +96 -13
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1,102 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var immer = require('immer');
|
|
6
|
+
var reactantModule = require('reactant-module');
|
|
7
|
+
|
|
8
|
+
/*! *****************************************************************************
|
|
9
|
+
Copyright (c) Microsoft Corporation.
|
|
10
|
+
|
|
11
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
12
|
+
purpose with or without fee is hereby granted.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
15
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
16
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
17
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
18
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
19
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
21
|
+
***************************************************************************** */
|
|
22
|
+
|
|
23
|
+
var __assign = function() {
|
|
24
|
+
__assign = Object.assign || function __assign(t) {
|
|
25
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
26
|
+
s = arguments[i];
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
28
|
+
}
|
|
29
|
+
return t;
|
|
30
|
+
};
|
|
31
|
+
return __assign.apply(this, arguments);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function __read(o, n) {
|
|
35
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
36
|
+
if (!m) return o;
|
|
37
|
+
var i = m.call(o), r, ar = [], e;
|
|
38
|
+
try {
|
|
39
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
40
|
+
}
|
|
41
|
+
catch (error) { e = { error: error }; }
|
|
42
|
+
finally {
|
|
43
|
+
try {
|
|
44
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
45
|
+
}
|
|
46
|
+
finally { if (e) throw e.error; }
|
|
47
|
+
}
|
|
48
|
+
return ar;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function __spreadArray(to, from, pack) {
|
|
52
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
53
|
+
if (ar || !(i in from)) {
|
|
54
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
55
|
+
ar[i] = from[i];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var model = function (scheme) {
|
|
62
|
+
var _a;
|
|
63
|
+
var module;
|
|
64
|
+
Object.keys(scheme.actions).forEach(function (key) {
|
|
65
|
+
var _a;
|
|
66
|
+
var fn = scheme.actions[key];
|
|
67
|
+
Object.assign(scheme.actions, (_a = {},
|
|
68
|
+
_a[key] = function () {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
var _c;
|
|
71
|
+
var args = [];
|
|
72
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
73
|
+
args[_i] = arguments[_i];
|
|
74
|
+
}
|
|
75
|
+
var state;
|
|
76
|
+
var patches;
|
|
77
|
+
var inversePatches;
|
|
78
|
+
if (module[reactantModule.enablePatchesKey]) {
|
|
79
|
+
_a = __read(immer.produceWithPatches(module[reactantModule.stateKey], function (draftState) {
|
|
80
|
+
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
81
|
+
}), 3), state = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
state = immer.produce(module[reactantModule.stateKey], function (draftState) {
|
|
85
|
+
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
var lastState = (_c = module[reactantModule.storeKey]) === null || _c === void 0 ? void 0 : _c.getState();
|
|
89
|
+
module[reactantModule.storeKey].dispatch(__assign({ type: module[reactantModule.identifierKey], method: key, state: __assign(__assign({}, lastState), (_b = {}, _b[module[reactantModule.identifierKey]] = state, _b)), _reactant: reactantModule.actionIdentifier }, (module[reactantModule.enablePatchesKey]
|
|
90
|
+
? {
|
|
91
|
+
_patches: patches,
|
|
92
|
+
_inversePatches: inversePatches,
|
|
93
|
+
}
|
|
94
|
+
: {})));
|
|
95
|
+
},
|
|
96
|
+
_a));
|
|
97
|
+
});
|
|
98
|
+
module = __assign((_a = {}, _a[reactantModule.nameKey] = scheme.name, _a[reactantModule.stateKey] = __assign({}, scheme.state), _a), scheme.actions);
|
|
99
|
+
return module;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
exports.model = model;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,15 +1,98 @@
|
|
|
1
|
-
import{produce
|
|
2
|
-
|
|
3
|
-
Copyright (c) Microsoft Corporation.
|
|
1
|
+
import { produce, produceWithPatches } from 'immer';
|
|
2
|
+
import { enablePatchesKey, stateKey, storeKey, identifierKey, actionIdentifier, nameKey } from 'reactant-module';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/*! *****************************************************************************
|
|
5
|
+
Copyright (c) Microsoft Corporation.
|
|
6
|
+
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
+
purpose with or without fee is hereby granted.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
17
|
+
***************************************************************************** */
|
|
18
|
+
|
|
19
|
+
var __assign = function() {
|
|
20
|
+
__assign = Object.assign || function __assign(t) {
|
|
21
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
22
|
+
s = arguments[i];
|
|
23
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
};
|
|
27
|
+
return __assign.apply(this, arguments);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function __read(o, n) {
|
|
31
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
32
|
+
if (!m) return o;
|
|
33
|
+
var i = m.call(o), r, ar = [], e;
|
|
34
|
+
try {
|
|
35
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
36
|
+
}
|
|
37
|
+
catch (error) { e = { error: error }; }
|
|
38
|
+
finally {
|
|
39
|
+
try {
|
|
40
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
41
|
+
}
|
|
42
|
+
finally { if (e) throw e.error; }
|
|
43
|
+
}
|
|
44
|
+
return ar;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function __spreadArray(to, from, pack) {
|
|
48
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
49
|
+
if (ar || !(i in from)) {
|
|
50
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
51
|
+
ar[i] = from[i];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
55
|
+
}
|
|
7
56
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
57
|
+
var model = function (scheme) {
|
|
58
|
+
var _a;
|
|
59
|
+
var module;
|
|
60
|
+
Object.keys(scheme.actions).forEach(function (key) {
|
|
61
|
+
var _a;
|
|
62
|
+
var fn = scheme.actions[key];
|
|
63
|
+
Object.assign(scheme.actions, (_a = {},
|
|
64
|
+
_a[key] = function () {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
var _c;
|
|
67
|
+
var args = [];
|
|
68
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
69
|
+
args[_i] = arguments[_i];
|
|
70
|
+
}
|
|
71
|
+
var state;
|
|
72
|
+
var patches;
|
|
73
|
+
var inversePatches;
|
|
74
|
+
if (module[enablePatchesKey]) {
|
|
75
|
+
_a = __read(produceWithPatches(module[stateKey], function (draftState) {
|
|
76
|
+
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
77
|
+
}), 3), state = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
state = produce(module[stateKey], function (draftState) {
|
|
81
|
+
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
var lastState = (_c = module[storeKey]) === null || _c === void 0 ? void 0 : _c.getState();
|
|
85
|
+
module[storeKey].dispatch(__assign({ type: module[identifierKey], method: key, state: __assign(__assign({}, lastState), (_b = {}, _b[module[identifierKey]] = state, _b)), _reactant: actionIdentifier }, (module[enablePatchesKey]
|
|
86
|
+
? {
|
|
87
|
+
_patches: patches,
|
|
88
|
+
_inversePatches: inversePatches,
|
|
89
|
+
}
|
|
90
|
+
: {})));
|
|
91
|
+
},
|
|
92
|
+
_a));
|
|
93
|
+
});
|
|
94
|
+
module = __assign((_a = {}, _a[nameKey] = scheme.name, _a[stateKey] = __assign({}, scheme.state), _a), scheme.actions);
|
|
95
|
+
return module;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export { model };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactant-model",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "A model lib for Reactant",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"unpkg": "dist/index.umd.js",
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"immer": "^9.0.5",
|
|
21
|
-
"reactant-module": "^0.
|
|
21
|
+
"reactant-module": "^0.37.0"
|
|
22
22
|
}
|
|
23
23
|
}
|