reactant-model 0.70.0 → 0.72.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/build/model.js +11 -4
- package/build/model.js.map +1 -1
- package/dist/index.cjs.js +10 -3
- package/dist/index.esm.js +11 -4
- package/dist/index.umd.js +1 -1
- package/dist/model.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/model.ts +21 -6
- package/test/index.test.ts +1 -1
package/build/model.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __assign, __read, __spreadArray } from "tslib";
|
|
2
|
-
import {
|
|
3
|
-
import { storeKey, stateKey, actionIdentifier, enablePatchesKey, identifierKey, nameKey, } from 'reactant-module';
|
|
2
|
+
import { create } from 'mutative';
|
|
3
|
+
import { storeKey, stateKey, actionIdentifier, enablePatchesKey, enableAutoFreezeKey, identifierKey, nameKey, strictKey, } from 'reactant-module';
|
|
4
4
|
export var model = function (scheme) {
|
|
5
5
|
var _a;
|
|
6
6
|
var module;
|
|
@@ -19,13 +19,20 @@ export var model = function (scheme) {
|
|
|
19
19
|
var patches;
|
|
20
20
|
var inversePatches;
|
|
21
21
|
if (module[enablePatchesKey]) {
|
|
22
|
-
_a = __read(
|
|
22
|
+
_a = __read(create(module[stateKey], function (draftState) {
|
|
23
23
|
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
24
|
+
}, {
|
|
25
|
+
enablePatches: true,
|
|
26
|
+
strict: module[strictKey],
|
|
27
|
+
enableAutoFreeze: module[enableAutoFreezeKey],
|
|
24
28
|
}), 3), state = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
25
29
|
}
|
|
26
30
|
else {
|
|
27
|
-
state =
|
|
31
|
+
state = create(module[stateKey], function (draftState) {
|
|
28
32
|
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
33
|
+
}, {
|
|
34
|
+
strict: module[strictKey],
|
|
35
|
+
enableAutoFreeze: module[enableAutoFreezeKey],
|
|
29
36
|
});
|
|
30
37
|
}
|
|
31
38
|
var lastState = (_c = module[storeKey]) === null || _c === void 0 ? void 0 : _c.getState();
|
package/build/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAa,MAAM,UAAU,CAAC;AAC7C,OAAO,EACL,QAAQ,EAER,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,OAAO,EACP,SAAS,GAEV,MAAM,iBAAiB,CAAC;AAYzB,MAAM,CAAC,IAAM,KAAK,GAAG,UAInB,MAAoB;;IAEpB,IAAI,MAAkB,CAAC;IACvB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAC,GAAG;;QACtC,IAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;YAC1B,GAAC,GAAG,IAAG;;;gBAAC,cAAc;qBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;oBAAd,yBAAc;;gBACpB,IAAI,KAAmC,CAAC;gBACxC,IAAI,OAA4B,CAAC;gBACjC,IAAI,cAAmC,CAAC;gBACxC,IAAI,MAAM,CAAC,gBAAgB,CAAC,EAAE;oBAC5B,KAAA,OAAmC,MAAM,CACvC,MAAM,CAAC,QAAQ,CAAM,EACrB,UAAC,UAAa;wBACZ,EAAE,wCAAI,IAAI,WAAE,UAAU,CAAC,CAAC;oBAC1B,CAAC,EACD;wBACE,aAAa,EAAE,IAAI;wBACnB,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC;wBACzB,gBAAgB,EAAE,MAAM,CAAC,mBAAmB,CAAC;qBAC9C,CACF,IAAA,EAVA,KAAK,QAAA,EAAE,OAAO,QAAA,EAAE,cAAc,QAAA,CAU7B;iBACH;qBAAM;oBACL,KAAK,GAAG,MAAM,CACZ,MAAM,CAAC,QAAQ,CAAM,EACrB,UAAC,UAAa;wBACZ,EAAE,wCAAI,IAAI,WAAE,UAAU,CAAC,CAAC;oBAC1B,CAAC,EACD;wBACE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC;wBACzB,gBAAgB,EAAE,MAAM,CAAC,mBAAmB,CAAC;qBAC9C,CACF,CAAC;iBACH;gBACD,IAAM,SAAS,GAAG,MAAA,MAAM,CAAC,QAAQ,CAAC,0CAAE,QAAQ,EAAE,CAAC;gBAC/C,MAAM,CAAC,QAAQ,CAAE,CAAC,QAAQ,YACxB,IAAI,EAAE,MAAM,CAAC,aAAa,CAAC,EAC3B,MAAM,EAAE,GAAG,EACX,KAAK,wBACA,SAAS,gBACX,MAAM,CAAC,aAAa,CAAE,IAAG,KAAK,QAEjC,SAAS,EAAE,gBAAgB,IACxB,CAAC,MAAM,CAAC,gBAAgB,CAAC;oBAC1B,CAAC,CAAC;wBACE,QAAQ,EAAE,OAAO;wBACjB,eAAe,EAAE,cAAc;qBAChC;oBACH,CAAC,CAAC,EAAE,CAAC,EACP,CAAC;YACL,CAAC;gBACD,CAAC;IACL,CAAC,CAAC,CAAC;IACH,MAAM,yBACH,OAAO,IAAG,MAAM,CAAC,IAAI,KACrB,QAAQ,iBACJ,MAAM,CAAC,KAAK,QAEd,MAAM,CAAC,OAAO,CAClB,CAAC;IACF,OAAO,MAAa,CAAC;AACvB,CAAC,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var mutative = require('mutative');
|
|
6
6
|
var reactantModule = require('reactant-module');
|
|
7
7
|
|
|
8
8
|
/******************************************************************************
|
|
@@ -76,13 +76,20 @@ var model = function (scheme) {
|
|
|
76
76
|
var patches;
|
|
77
77
|
var inversePatches;
|
|
78
78
|
if (module[reactantModule.enablePatchesKey]) {
|
|
79
|
-
_a = __read(
|
|
79
|
+
_a = __read(mutative.create(module[reactantModule.stateKey], function (draftState) {
|
|
80
80
|
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
81
|
+
}, {
|
|
82
|
+
enablePatches: true,
|
|
83
|
+
strict: module[reactantModule.strictKey],
|
|
84
|
+
enableAutoFreeze: module[reactantModule.enableAutoFreezeKey],
|
|
81
85
|
}), 3), state = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
82
86
|
}
|
|
83
87
|
else {
|
|
84
|
-
state =
|
|
88
|
+
state = mutative.create(module[reactantModule.stateKey], function (draftState) {
|
|
85
89
|
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
90
|
+
}, {
|
|
91
|
+
strict: module[reactantModule.strictKey],
|
|
92
|
+
enableAutoFreeze: module[reactantModule.enableAutoFreezeKey],
|
|
86
93
|
});
|
|
87
94
|
}
|
|
88
95
|
var lastState = (_c = module[reactantModule.storeKey]) === null || _c === void 0 ? void 0 : _c.getState();
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { enablePatchesKey, stateKey, storeKey, identifierKey, actionIdentifier, nameKey } from 'reactant-module';
|
|
1
|
+
import { create } from 'mutative';
|
|
2
|
+
import { enablePatchesKey, stateKey, strictKey, enableAutoFreezeKey, storeKey, identifierKey, actionIdentifier, nameKey } from 'reactant-module';
|
|
3
3
|
|
|
4
4
|
/******************************************************************************
|
|
5
5
|
Copyright (c) Microsoft Corporation.
|
|
@@ -72,13 +72,20 @@ var model = function (scheme) {
|
|
|
72
72
|
var patches;
|
|
73
73
|
var inversePatches;
|
|
74
74
|
if (module[enablePatchesKey]) {
|
|
75
|
-
_a = __read(
|
|
75
|
+
_a = __read(create(module[stateKey], function (draftState) {
|
|
76
76
|
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
77
|
+
}, {
|
|
78
|
+
enablePatches: true,
|
|
79
|
+
strict: module[strictKey],
|
|
80
|
+
enableAutoFreeze: module[enableAutoFreezeKey],
|
|
77
81
|
}), 3), state = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
78
82
|
}
|
|
79
83
|
else {
|
|
80
|
-
state =
|
|
84
|
+
state = create(module[stateKey], function (draftState) {
|
|
81
85
|
fn.apply(void 0, __spreadArray([], __read(args), false))(draftState);
|
|
86
|
+
}, {
|
|
87
|
+
strict: module[strictKey],
|
|
88
|
+
enableAutoFreeze: module[enableAutoFreezeKey],
|
|
82
89
|
});
|
|
83
90
|
}
|
|
84
91
|
var lastState = (_c = module[storeKey]) === null || _c === void 0 ? void 0 : _c.getState();
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mutative"),require("reactant-module")):"function"==typeof define&&define.amd?define(["exports","mutative","reactant-module"],t):t((e=e||self).reactantModel={},e.mutative,e.reactantModule)}(this,(function(e,t,r){"use strict";var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},n.apply(this,arguments)};function a(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,a,o=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)i.push(n.value)}catch(e){a={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(a)throw a.error}}return i}function o(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}e.model=function(e){var i,c;return Object.keys(e.actions).forEach((function(i){var l,s=e.actions[i];Object.assign(e.actions,((l={})[i]=function(){for(var e,l,u,f,y,d,p=[],v=0;v<arguments.length;v++)p[v]=arguments[v];c[r.enablePatchesKey]?(f=(e=a(t.create(c[r.stateKey],(function(e){s.apply(void 0,o([],a(p),!1))(e)}),{enablePatches:!0,strict:c[r.strictKey],enableAutoFreeze:c[r.enableAutoFreezeKey]}),3))[0],y=e[1],d=e[2]):f=t.create(c[r.stateKey],(function(e){s.apply(void 0,o([],a(p),!1))(e)}),{strict:c[r.strictKey],enableAutoFreeze:c[r.enableAutoFreezeKey]});var h=null===(u=c[r.storeKey])||void 0===u?void 0:u.getState();c[r.storeKey].dispatch(n({type:c[r.identifierKey],method:i,state:n(n({},h),(l={},l[c[r.identifierKey]]=f,l)),_reactant:r.actionIdentifier},c[r.enablePatchesKey]?{_patches:y,_inversePatches:d}:{}))},l))})),c=n(((i={})[r.nameKey]=e.name,i[r.stateKey]=n({},e.state),i),e.actions)},Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,OAAO,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,OAAO,EASR,MAAM,iBAAiB,CAAC;AAEzB,UAAU,MAAM,CAAC,CAAC,EAAE,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,aAAK,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,IAAI;KAC/D,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;CAC1D,CAAC;AAEF,eAAO,MAAM,KAAK,qEAEmB,GAAG,EAAE,mBAAmB,IAAI,+BA+DhE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactant-model",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.72.0",
|
|
4
4
|
"description": "A model lib for Reactant",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"unpkg": "dist/index.umd.js",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"
|
|
24
|
+
"mutative": "^0.4.2",
|
|
25
25
|
"reactant-module": "*"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"
|
|
29
|
-
"reactant-module": "^0.
|
|
28
|
+
"mutative": "^0.4.2",
|
|
29
|
+
"reactant-module": "^0.72.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/model.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { create, Immutable } from 'mutative';
|
|
2
2
|
import {
|
|
3
3
|
storeKey,
|
|
4
4
|
Service,
|
|
5
5
|
stateKey,
|
|
6
6
|
actionIdentifier,
|
|
7
7
|
enablePatchesKey,
|
|
8
|
+
enableAutoFreezeKey,
|
|
8
9
|
identifierKey,
|
|
9
10
|
nameKey,
|
|
11
|
+
strictKey,
|
|
12
|
+
Patch,
|
|
10
13
|
} from 'reactant-module';
|
|
11
14
|
|
|
12
15
|
interface Scheme<S, A> {
|
|
@@ -34,16 +37,28 @@ export const model = <
|
|
|
34
37
|
let patches: Patch[] | undefined;
|
|
35
38
|
let inversePatches: Patch[] | undefined;
|
|
36
39
|
if (module[enablePatchesKey]) {
|
|
37
|
-
[state, patches, inversePatches] =
|
|
38
|
-
module[stateKey],
|
|
40
|
+
[state, patches, inversePatches] = create(
|
|
41
|
+
module[stateKey] as S,
|
|
39
42
|
(draftState: S) => {
|
|
40
43
|
fn(...args)(draftState);
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
enablePatches: true,
|
|
47
|
+
strict: module[strictKey],
|
|
48
|
+
enableAutoFreeze: module[enableAutoFreezeKey],
|
|
41
49
|
}
|
|
42
50
|
);
|
|
43
51
|
} else {
|
|
44
|
-
state =
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
state = create(
|
|
53
|
+
module[stateKey] as S,
|
|
54
|
+
(draftState: S) => {
|
|
55
|
+
fn(...args)(draftState);
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
strict: module[strictKey],
|
|
59
|
+
enableAutoFreeze: module[enableAutoFreezeKey],
|
|
60
|
+
}
|
|
61
|
+
);
|
|
47
62
|
}
|
|
48
63
|
const lastState = module[storeKey]?.getState();
|
|
49
64
|
module[storeKey]!.dispatch({
|
package/test/index.test.ts
CHANGED