reactant-model 0.149.0 → 0.150.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.
@@ -0,0 +1 @@
1
+ export { model } from './model.js';
@@ -0,0 +1,53 @@
1
+ import { __read, __spreadArray, __assign } from './node_modules/tslib/tslib.es6.js';
2
+ import { create } from 'mutative';
3
+ import { enablePatchesKey, stateKey, enableAutoFreezeKey, strictKey, storeKey, identifierKey, nameKey, actionIdentifier } from 'reactant-module';
4
+
5
+ var model = function (scheme) {
6
+ var _a;
7
+ var module;
8
+ Object.keys(scheme.actions).forEach(function (key) {
9
+ var _a;
10
+ var fn = scheme.actions[key];
11
+ Object.assign(scheme.actions, (_a = {},
12
+ _a[key] = function () {
13
+ var _a, _b;
14
+ var _c;
15
+ var args = [];
16
+ for (var _i = 0; _i < arguments.length; _i++) {
17
+ args[_i] = arguments[_i];
18
+ }
19
+ var state;
20
+ var patches;
21
+ var inversePatches;
22
+ if (module[enablePatchesKey]) {
23
+ _a = __read(create(module[stateKey], function (draftState) {
24
+ fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
25
+ }, {
26
+ enablePatches: true,
27
+ strict: module[strictKey],
28
+ enableAutoFreeze: module[enableAutoFreezeKey],
29
+ }), 3), state = _a[0], patches = _a[1], inversePatches = _a[2];
30
+ }
31
+ else {
32
+ state = create(module[stateKey], function (draftState) {
33
+ fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
34
+ }, {
35
+ strict: module[strictKey],
36
+ enableAutoFreeze: module[enableAutoFreezeKey],
37
+ });
38
+ }
39
+ var lastState = (_c = module[storeKey]) === null || _c === void 0 ? void 0 : _c.getState();
40
+ module[storeKey].dispatch(__assign({ type: module[identifierKey], method: key, state: __assign(__assign({}, lastState), (_b = {}, _b[module[identifierKey]] = state, _b)), _reactant: actionIdentifier }, (module[enablePatchesKey]
41
+ ? {
42
+ _patches: patches,
43
+ _inversePatches: inversePatches,
44
+ }
45
+ : {})));
46
+ },
47
+ _a));
48
+ });
49
+ module = __assign((_a = {}, _a[nameKey] = scheme.name, _a[stateKey] = __assign({}, scheme.state), _a), scheme.actions);
50
+ return module;
51
+ };
52
+
53
+ export { model };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "reactant-model",
3
- "version": "0.149.0",
3
+ "version": "0.150.0",
4
4
  "description": "A model lib for Reactant",
5
5
  "main": "dist/index.cjs.js",
6
6
  "unpkg": "dist/index.umd.js",
7
- "module": "dist/index.esm.js",
7
+ "module": "dist/esm/index.js",
8
8
  "types": "dist/index.d.ts",
9
+ "sideEffects": false,
9
10
  "typedoc": {
10
11
  "entryPoint": "src/index.ts"
11
12
  },
@@ -32,6 +33,6 @@
32
33
  },
33
34
  "devDependencies": {
34
35
  "mutative": "^1.3.0",
35
- "reactant-module": "^0.149.0"
36
+ "reactant-module": "^0.150.0"
36
37
  }
37
38
  }