@coaction/mobx 0.1.4 → 0.1.5
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.
|
@@ -7,13 +7,13 @@ var coaction = require('coaction');
|
|
|
7
7
|
var mobx = require('mobx');
|
|
8
8
|
|
|
9
9
|
const instancesMap = new WeakMap();
|
|
10
|
-
const handleStore = store => {
|
|
11
|
-
if (
|
|
12
|
-
|
|
10
|
+
const handleStore = (store, rawState, state, internal) => {
|
|
11
|
+
if (internal.toMutableRaw) return;
|
|
12
|
+
internal.toMutableRaw = key => instancesMap.get(key);
|
|
13
13
|
Object.assign(store, {
|
|
14
14
|
subscribe: mobx.autorun
|
|
15
15
|
});
|
|
16
|
-
|
|
16
|
+
internal.actMutable = mobx.runInAction;
|
|
17
17
|
store.apply = (state = store.getState(), patches) => {
|
|
18
18
|
if (!patches) {
|
|
19
19
|
if (store.isSliceStore) {
|
|
@@ -3,13 +3,13 @@ import { createBinder } from 'coaction';
|
|
|
3
3
|
import { autorun, runInAction } from 'mobx';
|
|
4
4
|
|
|
5
5
|
const instancesMap = new WeakMap();
|
|
6
|
-
const handleStore = store => {
|
|
7
|
-
if (
|
|
8
|
-
|
|
6
|
+
const handleStore = (store, rawState, state, internal) => {
|
|
7
|
+
if (internal.toMutableRaw) return;
|
|
8
|
+
internal.toMutableRaw = key => instancesMap.get(key);
|
|
9
9
|
Object.assign(store, {
|
|
10
10
|
subscribe: autorun
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
internal.actMutable = runInAction;
|
|
13
13
|
store.apply = (state = store.getState(), patches) => {
|
|
14
14
|
if (!patches) {
|
|
15
15
|
if (store.isSliceStore) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mutative"),require("coaction"),require("mobx")):"function"==typeof define&&define.amd?define(["exports","mutative","coaction","mobx"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CoactionMobx={},e.Mutative,e.Coaction,e.Mobx)}(this,(function(e,t,r,n){"use strict";const o="replace";function a(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function c(e,t){return 2===a(e)?e.get(t):e[t]}function i(e){if("object"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map(i);if(e instanceof Map)return new Map(Array.from(e.entries()).map((([e,t])=>[e,i(t)])));if(e instanceof Set)return new Set(Array.from(e).map(i));const t=Object.create(Object.getPrototypeOf(e));for(const r in e)t[r]=i(e[r]);return t}const s=new WeakMap,u=r.createBinder({handleStore:e=>{
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mutative"),require("coaction"),require("mobx")):"function"==typeof define&&define.amd?define(["exports","mutative","coaction","mobx"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CoactionMobx={},e.Mutative,e.Coaction,e.Mobx)}(this,(function(e,t,r,n){"use strict";const o="replace";function a(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function c(e,t){return 2===a(e)?e.get(t):e[t]}function i(e){if("object"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map(i);if(e instanceof Map)return new Map(Array.from(e.entries()).map((([e,t])=>[e,i(t)])));if(e instanceof Set)return new Set(Array.from(e).map(i));const t=Object.create(Object.getPrototypeOf(e));for(const r in e)t[r]=i(e[r]);return t}const s=new WeakMap,u=r.createBinder({handleStore:(e,t,r,u)=>{u.toMutableRaw||(u.toMutableRaw=e=>s.get(e),Object.assign(e,{subscribe:n.autorun}),u.actMutable=n.runInAction,e.apply=(t=e.getState(),r)=>{r?n.runInAction((()=>{!function(e,t){let r;for(r=t.length-1;r>=0;r-=1){const{value:n,op:a,path:c}=t[r];if(!c.length&&a===o||""===c&&"add"===a){e=n;break}}r>-1&&(t=t.slice(r+1)),t.forEach((t=>{const{path:r,op:n}=t,s=function(e){return Array.isArray(e)?e:e.split("/").map((e=>e.replace(/~1/g,"/").replace(/~0/g,"~"))).slice(1)}(r);let u=e;for(let e=0;e<s.length-1;e+=1){const t=a(u);let r=s[e];if("string"!=typeof r&&"number"!=typeof r&&(r=String(r)),(0===t||1===t)&&("__proto__"===r||"constructor"===r)||"function"==typeof u&&"prototype"===r)throw new Error("Patching reserved attributes like __proto__ and constructor is not allowed.");if(u=c(3===a(u)?Array.from(u):u,r),"object"!=typeof u)throw new Error(`Cannot apply patch at '${s.join("/")}'.`)}const p=a(u),f=i(t.value),l=s[s.length-1];switch(n){case o:switch(p){case 2:return u.set(l,f);case 3:throw new Error("Cannot apply replace patch to set.");default:return u[l]=f}case"add":switch(p){case 1:return"-"===l?u.push(f):u.splice(l,0,f);case 2:return u.set(l,f);case 3:return u.add(f);default:return u[l]=f}case"remove":switch(p){case 1:return u.splice(l,1);case 2:return u.delete(l);case 3:return u.delete(t.value);default:return delete u[l]}default:throw new Error(`Unsupported patch operation: ${n}.`)}}))}(t,r)})):e.isSliceStore?"object"==typeof t&&null!==t&&n.runInAction((()=>{for(const r in t){const n=r,o=t[n];"object"==typeof o&&null!==o&&Object.assign(e.getState()[n],o)}})):n.runInAction((()=>{Object.assign(e.getState(),t)}))})},handleState:e=>{const t=Object.getOwnPropertyDescriptors(e),r=Object.defineProperties({},t),n=Object.defineProperties({},t);return{copyState:r,bind:e=>(s.set(n,e),n)}}});e.bindMobx=u,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=coaction-mobx.umd.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coaction-mobx.umd.min.js","sources":["../../../node_modules/mutability/dist/index.esm.js","../src/index.ts"],"sourcesContent":["import{create as e}from\"mutative\";const t=\"remove\",r=\"replace\",n=\"add\";function o(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function a(e,t){return 2===o(e)?e.get(t):e[t]}function c(e){if(\"object\"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map(c);if(e instanceof Map)return new Map(Array.from(e.entries()).map((([e,t])=>[e,c(t)])));if(e instanceof Set)return new Set(Array.from(e).map(c));const t=Object.create(Object.getPrototypeOf(e));for(const r in e)t[r]=c(e[r]);return t}function s(e,s){let i;for(i=s.length-1;i>=0;i-=1){const{value:t,op:o,path:a}=s[i];if(!a.length&&o===r||\"\"===a&&o===n){e=t;break}}i>-1&&(s=s.slice(i+1)),s.forEach((s=>{const{path:i,op:p}=s,u=function(e){return Array.isArray(e)?e:e.split(\"/\").map((e=>e.replace(/~1/g,\"/\").replace(/~0/g,\"~\"))).slice(1)}(i);let f=e;for(let e=0;e<u.length-1;e+=1){const t=o(f);let r=u[e];if(\"string\"!=typeof r&&\"number\"!=typeof r&&(r=String(r)),(0===t||1===t)&&(\"__proto__\"===r||\"constructor\"===r)||\"function\"==typeof f&&\"prototype\"===r)throw new Error(\"Patching reserved attributes like __proto__ and constructor is not allowed.\");if(f=a(3===o(f)?Array.from(f):f,r),\"object\"!=typeof f)throw new Error(`Cannot apply patch at '${u.join(\"/\")}'.`)}const l=o(f),h=c(s.value),y=u[u.length-1];switch(p){case r:switch(l){case 2:return f.set(y,h);case 3:throw new Error(\"Cannot apply replace patch to set.\");default:return f[y]=h}case n:switch(l){case 1:return\"-\"===y?f.push(h):f.splice(y,0,h);case 2:return f.set(y,h);case 3:return f.add(h);default:return f[y]=h}case t:switch(l){case 1:return f.splice(y,1);case 2:return f.delete(y);case 3:return f.delete(s.value);default:return delete f[y]}default:throw new Error(`Unsupported patch operation: ${p}.`)}}))}const i=(t,r)=>{const[,n,o]=e(t,r,{enablePatches:!0});return s(t,n),{inversePatches:o,patches:n}};export{s as apply,i as mutate};\n//# sourceMappingURL=index.esm.js.map\n","import { apply } from 'mutability';\nimport { type Store, createBinder } from 'coaction';\nimport { autorun, runInAction } from 'mobx';\n\nconst instancesMap = new WeakMap<object, object>();\n\nconst handleStore = (store: Store<object
|
|
1
|
+
{"version":3,"file":"coaction-mobx.umd.min.js","sources":["../../../node_modules/mutability/dist/index.esm.js","../src/index.ts"],"sourcesContent":["import{create as e}from\"mutative\";const t=\"remove\",r=\"replace\",n=\"add\";function o(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function a(e,t){return 2===o(e)?e.get(t):e[t]}function c(e){if(\"object\"!=typeof e||null===e)return e;if(Array.isArray(e))return e.map(c);if(e instanceof Map)return new Map(Array.from(e.entries()).map((([e,t])=>[e,c(t)])));if(e instanceof Set)return new Set(Array.from(e).map(c));const t=Object.create(Object.getPrototypeOf(e));for(const r in e)t[r]=c(e[r]);return t}function s(e,s){let i;for(i=s.length-1;i>=0;i-=1){const{value:t,op:o,path:a}=s[i];if(!a.length&&o===r||\"\"===a&&o===n){e=t;break}}i>-1&&(s=s.slice(i+1)),s.forEach((s=>{const{path:i,op:p}=s,u=function(e){return Array.isArray(e)?e:e.split(\"/\").map((e=>e.replace(/~1/g,\"/\").replace(/~0/g,\"~\"))).slice(1)}(i);let f=e;for(let e=0;e<u.length-1;e+=1){const t=o(f);let r=u[e];if(\"string\"!=typeof r&&\"number\"!=typeof r&&(r=String(r)),(0===t||1===t)&&(\"__proto__\"===r||\"constructor\"===r)||\"function\"==typeof f&&\"prototype\"===r)throw new Error(\"Patching reserved attributes like __proto__ and constructor is not allowed.\");if(f=a(3===o(f)?Array.from(f):f,r),\"object\"!=typeof f)throw new Error(`Cannot apply patch at '${u.join(\"/\")}'.`)}const l=o(f),h=c(s.value),y=u[u.length-1];switch(p){case r:switch(l){case 2:return f.set(y,h);case 3:throw new Error(\"Cannot apply replace patch to set.\");default:return f[y]=h}case n:switch(l){case 1:return\"-\"===y?f.push(h):f.splice(y,0,h);case 2:return f.set(y,h);case 3:return f.add(h);default:return f[y]=h}case t:switch(l){case 1:return f.splice(y,1);case 2:return f.delete(y);case 3:return f.delete(s.value);default:return delete f[y]}default:throw new Error(`Unsupported patch operation: ${p}.`)}}))}const i=(t,r)=>{const[,n,o]=e(t,r,{enablePatches:!0});return s(t,n),{inversePatches:o,patches:n}};export{s as apply,i as mutate};\n//# sourceMappingURL=index.esm.js.map\n","import { apply } from 'mutability';\nimport { type Store, createBinder } from 'coaction';\nimport { autorun, runInAction } from 'mobx';\n\nconst instancesMap = new WeakMap<object, object>();\n\nconst handleStore = (\n store: Store<object>,\n rawState: object,\n state: object,\n internal: any\n) => {\n if (internal.toMutableRaw) return;\n internal.toMutableRaw = (key: object) => instancesMap.get(key);\n Object.assign(store, {\n subscribe: autorun\n });\n internal.actMutable = runInAction;\n store.apply = (state = store.getState(), patches) => {\n if (!patches) {\n if (store.isSliceStore) {\n if (typeof state === 'object' && state !== null) {\n runInAction(() => {\n for (const key in state) {\n const _key = key as keyof typeof state;\n const _state = state[_key];\n if (typeof _state === 'object' && _state !== null) {\n Object.assign(store.getState()[_key], _state);\n }\n }\n });\n }\n } else {\n runInAction(() => {\n Object.assign(store.getState(), state);\n });\n }\n return;\n }\n runInAction(() => {\n apply(state, patches!);\n });\n };\n};\n\ninterface BindMobx {\n <T>(target: T): T;\n}\n\n/**\n * Bind a store to Mobx\n */\nexport const bindMobx = createBinder<BindMobx>({\n handleStore,\n handleState: (options) => {\n const descriptors = Object.getOwnPropertyDescriptors(options);\n const copyState = Object.defineProperties(\n {},\n descriptors\n ) as typeof options;\n const rawState = Object.defineProperties({}, descriptors) as typeof options;\n return {\n copyState,\n bind: (state) => {\n instancesMap.set(rawState, state);\n return rawState;\n }\n };\n }\n});\n"],"names":["r","o","e","Array","isArray","Map","Set","a","t","get","c","map","from","entries","Object","create","getPrototypeOf","instancesMap","WeakMap","bindMobx","createBinder","handleStore","store","rawState","state","internal","toMutableRaw","key","assign","subscribe","autorun","actMutable","runInAction","apply","getState","patches","s","i","length","value","op","path","slice","forEach","p","u","split","replace","f","String","Error","join","l","h","y","set","push","splice","add","delete","isSliceStore","_key","_state","handleState","options","descriptors","getOwnPropertyDescriptors","copyState","defineProperties","bind"],"mappings":"4WAAkC,MAAiBA,EAAE,UAAkB,SAASC,EAAEC,GAAG,OAAOC,MAAMC,QAAQF,GAAG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AAOD,GAAG,KAAK,EAAE,OAAOJ,EAAES,OAAOH,EAAE,GAAG,KAAK,EAAE,OAAON,EAAEW,OAAOL,GAAG,KAAK,EAAE,OAAON,EAAEW,OAAOvB,EAAEG,OAAO,QAAQ,cAAcS,EAAEM,GAAG,QAAQ,MAAM,IAAIJ,MAAM,gCAAgCN,MAAO,GAAE,CCwC7sDX,CAAMT,EAAOW,EAAS,IApBlBb,EAAMsC,aACa,iBAAVpC,GAAgC,OAAVA,GAC/BQ,EAAAA,aAAY,KACV,IAAK,MAAML,KAAOH,EAAO,CACvB,MAAMqC,EAAOlC,EACPmC,EAAStC,EAAMqC,GACC,iBAAXC,GAAkC,OAAXA,GAChChD,OAAOc,OAAON,EAAMY,WAAW2B,GAAOC,EAE1C,KAIJ9B,EAAAA,aAAY,KACVlB,OAAOc,OAAON,EAAMY,WAAYV,EAAM,GAO1C,EACH,EAYDuC,YAAcC,IACZ,MAAMC,EAAcnD,OAAOoD,0BAA0BF,GAC/CG,EAAYrD,OAAOsD,iBACvB,CAAE,EACFH,GAEI1C,EAAWT,OAAOsD,iBAAiB,CAAE,EAAEH,GAC7C,MAAO,CACLE,YACAE,KAAO7C,IACLP,EAAasC,IAAIhC,EAAUC,GACpBD,GAEV"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coaction/mobx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "A Coaction integration tool for MobX",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
@@ -47,23 +47,32 @@
|
|
|
47
47
|
]
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"coaction": "^0.1.
|
|
50
|
+
"coaction": "^0.1.5",
|
|
51
51
|
"mobx": "^6.13.2",
|
|
52
52
|
"mutative": "^1.1.0",
|
|
53
|
-
"react": "^
|
|
53
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
56
56
|
"coaction": {
|
|
57
57
|
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"mobx": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"mutative": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"react": {
|
|
66
|
+
"optional": true
|
|
58
67
|
}
|
|
59
68
|
},
|
|
60
69
|
"devDependencies": {
|
|
61
70
|
"@testing-library/react": "^14.2.1",
|
|
62
71
|
"@types/jsdom": "^12.2.3",
|
|
63
|
-
"@types/react": "^
|
|
64
|
-
"@types/react-dom": "^
|
|
65
|
-
"@types/use-sync-external-store": "^0.0.
|
|
66
|
-
"coaction": "^0.1.
|
|
72
|
+
"@types/react": "^18.3.12",
|
|
73
|
+
"@types/react-dom": "^18.3.0",
|
|
74
|
+
"@types/use-sync-external-store": "^0.0.6",
|
|
75
|
+
"coaction": "^0.1.5",
|
|
67
76
|
"jsdom": "^25.0.1",
|
|
68
77
|
"jsdom-global": "^3.0.2",
|
|
69
78
|
"mobx": "^6.13.2",
|