@e7w/easy-model 0.1.3 → 0.1.4
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.es.js +79 -80
- package/dist/index.umd.js +1 -1
- package/package.json +2 -3
package/dist/index.es.js
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
1
|
+
import { useReducer as A, useEffect as L } from "react";
|
|
2
|
+
const M = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), j = Symbol("origin");
|
|
3
3
|
let d = null;
|
|
4
|
-
const
|
|
4
|
+
const _ = ["includes", "indexOf", "lastIndexOf"], T = [Promise, RegExp, Date, WeakMap, WeakSet, Map, Set];
|
|
5
5
|
function w(e) {
|
|
6
|
-
if (e = l(e), !e ||
|
|
7
|
-
if (
|
|
8
|
-
const n = {},
|
|
9
|
-
get(
|
|
10
|
-
if (t ===
|
|
11
|
-
let
|
|
12
|
-
return
|
|
6
|
+
if (e = l(e), !e || T.some((i) => e instanceof i)) return e;
|
|
7
|
+
if (M.has(e)) return M.get(e);
|
|
8
|
+
const n = {}, o = {}, c = new Proxy(e, {
|
|
9
|
+
get(i, t, s) {
|
|
10
|
+
if (t === j) return i;
|
|
11
|
+
let r = z(i, t);
|
|
12
|
+
return r || (r = Reflect.get(i, t, s), typeof r == "function" ? (o[t] || (o[t] = r.bind(w(i))), r = o[t]) : typeof r == "object" && r !== null && (n[t] || (n[t] = R(r, E(e, t))), r = w(r)), r);
|
|
13
13
|
},
|
|
14
|
-
set(
|
|
15
|
-
let u = Reflect.get(
|
|
14
|
+
set(i, t, s, r) {
|
|
15
|
+
let u = Reflect.get(i, t, r);
|
|
16
16
|
if (u = l(u), s = l(s), u === s) return !0;
|
|
17
|
-
const f = Reflect.set(
|
|
17
|
+
const f = Reflect.set(i, t, s, r);
|
|
18
18
|
if (f) {
|
|
19
|
-
n[t] && (n[t](), delete n[t]), typeof s == "object" && s !== null && (n[t] = R(s,
|
|
19
|
+
n[t] && (n[t](), delete n[t]), typeof s == "object" && s !== null && (n[t] = R(s, E(e, t))), o[t] && delete o[t];
|
|
20
20
|
const y = d;
|
|
21
|
-
d = /* @__PURE__ */ new WeakSet(), W(
|
|
21
|
+
d = /* @__PURE__ */ new WeakSet(), W(i, [t], u, s), d = y;
|
|
22
22
|
}
|
|
23
23
|
return f;
|
|
24
24
|
},
|
|
25
|
-
deleteProperty(
|
|
26
|
-
let s = Reflect.get(
|
|
25
|
+
deleteProperty(i, t) {
|
|
26
|
+
let s = Reflect.get(i, t);
|
|
27
27
|
s = l(s);
|
|
28
|
-
const
|
|
29
|
-
return
|
|
28
|
+
const r = Reflect.deleteProperty(i, t);
|
|
29
|
+
return r && (n[t] && (n[t](), delete n[t]), o[t] && delete o[t], W(i, [t], s, void 0)), r;
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
return
|
|
32
|
+
return M.set(e, c), c;
|
|
33
33
|
}
|
|
34
34
|
function R(e, n) {
|
|
35
35
|
e = l(e), p.has(e) || p.set(e, /* @__PURE__ */ new Map());
|
|
36
|
-
const
|
|
37
|
-
return
|
|
38
|
-
|
|
36
|
+
const o = p.get(e), c = Symbol();
|
|
37
|
+
return o.set(c, n), function() {
|
|
38
|
+
o.delete(c);
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
return function(...
|
|
43
|
-
const [
|
|
44
|
-
W(e, [n, ...
|
|
41
|
+
function E(e, n) {
|
|
42
|
+
return function(...o) {
|
|
43
|
+
const [c, ...i] = o;
|
|
44
|
+
W(e, [n, ...c], ...i);
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function W(e, ...n) {
|
|
48
48
|
if (e = l(e), d != null && d.has(e)) return;
|
|
49
49
|
d == null || d.add(e);
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
52
|
-
[...
|
|
50
|
+
const o = p.get(e);
|
|
51
|
+
if (!o) return;
|
|
52
|
+
[...o.values()].forEach((i) => {
|
|
53
53
|
const t = new EventTarget(), s = new Event("__trigger__");
|
|
54
|
-
t.addEventListener(s.type,
|
|
55
|
-
function
|
|
56
|
-
t.removeEventListener(s.type,
|
|
54
|
+
t.addEventListener(s.type, r), t.dispatchEvent(s);
|
|
55
|
+
function r() {
|
|
56
|
+
t.removeEventListener(s.type, r), i(...n);
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
function l(e) {
|
|
61
|
-
return typeof e != "object" || e === null ? e : e[
|
|
61
|
+
return typeof e != "object" || e === null ? e : e[j] ?? e;
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function z(e, n) {
|
|
64
64
|
if (e = l(e), ["constructor", "__proto__"].includes(n))
|
|
65
65
|
return Reflect.get(e, n);
|
|
66
66
|
if (n === "hasOwnProperty")
|
|
67
|
-
return function(
|
|
68
|
-
return Object.prototype.hasOwnProperty.call(l(this),
|
|
67
|
+
return function(o) {
|
|
68
|
+
return Object.prototype.hasOwnProperty.call(l(this), o);
|
|
69
69
|
};
|
|
70
|
-
if (Array.isArray(e) &&
|
|
71
|
-
return function(...
|
|
72
|
-
const
|
|
73
|
-
return
|
|
70
|
+
if (Array.isArray(e) && _.includes(n))
|
|
71
|
+
return function(...o) {
|
|
72
|
+
const c = _[n].apply(l(this), o);
|
|
73
|
+
return c === -1 || c === !1 ? _[n].apply(l(this), o.map(l)) : c;
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
const h = Symbol("instance"), b = /* @__PURE__ */ new WeakMap(),
|
|
77
|
-
function
|
|
78
|
-
if (
|
|
76
|
+
const h = Symbol("instance"), b = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakSet(), v = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap();
|
|
77
|
+
function U(e) {
|
|
78
|
+
if (O.has(e))
|
|
79
79
|
return e;
|
|
80
80
|
if (b.has(e))
|
|
81
81
|
return b.get(e);
|
|
@@ -86,73 +86,72 @@ function D(e) {
|
|
|
86
86
|
__proto__: e.prototype
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
|
-
get(s,
|
|
90
|
-
let f =
|
|
91
|
-
return f || (f = Reflect.get(s,
|
|
89
|
+
get(s, r, u) {
|
|
90
|
+
let f = z(s, r);
|
|
91
|
+
return f || (f = Reflect.get(s, r, u), typeof r == "symbol" || ["constructor", "__proto__"].includes(r) || typeof f != "function") ? f : (n[r] || (n[r] = function(...y) {
|
|
92
92
|
return f.apply(w(this), y);
|
|
93
|
-
}), n[
|
|
93
|
+
}), n[r]);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
);
|
|
97
|
-
const
|
|
98
|
-
({ args: s, token:
|
|
97
|
+
const o = /* @__PURE__ */ new Map(), c = new FinalizationRegistry(
|
|
98
|
+
({ args: s, token: r }) => {
|
|
99
99
|
var u;
|
|
100
|
-
F(
|
|
100
|
+
F(o, s), (u = m.get(r)) == null || u(), c.unregister(r);
|
|
101
101
|
}
|
|
102
|
-
),
|
|
103
|
-
apply(s,
|
|
102
|
+
), i = new Proxy(e, {
|
|
103
|
+
apply(s, r, u) {
|
|
104
104
|
var y, P, k, S;
|
|
105
|
-
let f =
|
|
105
|
+
let f = o;
|
|
106
106
|
for (let a = 0; a < u.length; a++)
|
|
107
107
|
f.has(u[a]) || f.set(u[a], /* @__PURE__ */ new Map()), f = f.get(u[a]);
|
|
108
108
|
if (!f.has(h) || f.get(h) !== void 0 && !((P = (y = f.get(h)) == null ? void 0 : y.deref) != null && P.call(y))) {
|
|
109
109
|
f.set(h, void 0);
|
|
110
110
|
const a = w(Reflect.construct(s, u, t));
|
|
111
111
|
f.set(h, new WeakRef(a));
|
|
112
|
-
const
|
|
113
|
-
|
|
112
|
+
const x = C(a);
|
|
113
|
+
c.register(a, { args: u, token: x }, x);
|
|
114
114
|
}
|
|
115
115
|
return (S = (k = f.get(h)) == null ? void 0 : k.deref) == null ? void 0 : S.call(k);
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
|
-
return b.set(e,
|
|
118
|
+
return b.set(e, i), O.add(i), b.get(e);
|
|
119
119
|
function t() {
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
function F(e, n) {
|
|
123
123
|
if (n.length === 0) return e.delete(h);
|
|
124
|
-
const [
|
|
125
|
-
if (!(
|
|
126
|
-
return e.delete(
|
|
124
|
+
const [o, ...c] = n, i = e.get(o);
|
|
125
|
+
if (!(i instanceof Map && (F(i, c), i.size > 0)))
|
|
126
|
+
return e.delete(o);
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
const n = w(e),
|
|
128
|
+
function g(e) {
|
|
129
|
+
const n = w(e), o = C(n);
|
|
130
130
|
return {
|
|
131
|
-
register(
|
|
132
|
-
|
|
131
|
+
register(c) {
|
|
132
|
+
o && m.set(o, c);
|
|
133
133
|
},
|
|
134
134
|
unregister() {
|
|
135
|
-
|
|
135
|
+
o && m.delete(o);
|
|
136
136
|
}
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const r = D(e), i = n ? r(...n) : G;
|
|
142
|
-
return I(i);
|
|
139
|
+
function C(e) {
|
|
140
|
+
return v.has(e) || v.set(e, {}), v.get(e);
|
|
143
141
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
142
|
+
const D = /* @__PURE__ */ Object.create(null);
|
|
143
|
+
function q(e, n) {
|
|
144
|
+
const o = U(e), c = n ? o(...n) : D;
|
|
145
|
+
return G(c);
|
|
146
|
+
}
|
|
147
|
+
function G(e) {
|
|
148
|
+
const [, n] = A((o) => (o + 1) % 100, 0);
|
|
149
|
+
return L(() => (n(), R(e, () => n())), [e]), e;
|
|
151
150
|
}
|
|
152
151
|
export {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
g as finalizationRegistry,
|
|
153
|
+
U as provide,
|
|
154
|
+
G as useInstance,
|
|
155
|
+
q as useModel,
|
|
157
156
|
R as watch
|
|
158
157
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,
|
|
1
|
+
(function(l,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],b):(l=typeof globalThis<"u"?globalThis:l||self,b(l["@e7w/easy-model"]={},l.React))})(this,function(l,b){"use strict";const R=new WeakMap,p=new WeakMap,O=Symbol("origin");let d=null;const W=["includes","indexOf","lastIndexOf"],L=[Promise,RegExp,Date,WeakMap,WeakSet,Map,Set];function k(e){if(e=a(e),!e||L.some(r=>e instanceof r))return e;if(R.has(e))return R.get(e);const n={},o={},c=new Proxy(e,{get(r,t,s){if(t===O)return r;let i=E(r,t);return i||(i=Reflect.get(r,t,s),typeof i=="function"?(o[t]||(o[t]=i.bind(k(r))),i=o[t]):typeof i=="object"&&i!==null&&(n[t]||(n[t]=M(i,j(e,t))),i=k(i)),i)},set(r,t,s,i){let u=Reflect.get(r,t,i);if(u=a(u),s=a(s),u===s)return!0;const f=Reflect.set(r,t,s,i);if(f){n[t]&&(n[t](),delete n[t]),typeof s=="object"&&s!==null&&(n[t]=M(s,j(e,t))),o[t]&&delete o[t];const h=d;d=new WeakSet,m(r,[t],u,s),d=h}return f},deleteProperty(r,t){let s=Reflect.get(r,t);s=a(s);const i=Reflect.deleteProperty(r,t);return i&&(n[t]&&(n[t](),delete n[t]),o[t]&&delete o[t],m(r,[t],s,void 0)),i}});return R.set(e,c),c}function M(e,n){e=a(e),p.has(e)||p.set(e,new Map);const o=p.get(e),c=Symbol();return o.set(c,n),function(){o.delete(c)}}function j(e,n){return function(...o){const[c,...r]=o;m(e,[n,...c],...r)}}function m(e,...n){if(e=a(e),d!=null&&d.has(e))return;d==null||d.add(e);const o=p.get(e);if(!o)return;[...o.values()].forEach(r=>{const t=new EventTarget,s=new Event("__trigger__");t.addEventListener(s.type,i),t.dispatchEvent(s);function i(){t.removeEventListener(s.type,i),r(...n)}})}function a(e){return typeof e!="object"||e===null?e:e[O]??e}function E(e,n){if(e=a(e),["constructor","__proto__"].includes(n))return Reflect.get(e,n);if(n==="hasOwnProperty")return function(o){return Object.prototype.hasOwnProperty.call(a(this),o)};if(Array.isArray(e)&&W.includes(n))return function(...o){const c=W[n].apply(a(this),o);return c===-1||c===!1?W[n].apply(a(this),o.map(a)):c}}const w=Symbol("instance"),_=new WeakMap,x=new WeakSet,S=new WeakMap,P=new WeakMap;function z(e){if(x.has(e))return e;if(_.has(e))return _.get(e);const n={};t.prototype=new Proxy({constructor:e,__proto__:e.prototype},{get(s,i,u){let f=E(s,i);return f||(f=Reflect.get(s,i,u),typeof i=="symbol"||["constructor","__proto__"].includes(i)||typeof f!="function")?f:(n[i]||(n[i]=function(...h){return f.apply(k(this),h)}),n[i])}});const o=new Map,c=new FinalizationRegistry(({args:s,token:i})=>{var u;T(o,s),(u=P.get(i))==null||u(),c.unregister(i)}),r=new Proxy(e,{apply(s,i,u){var h,g,v,A;let f=o;for(let y=0;y<u.length;y++)f.has(u[y])||f.set(u[y],new Map),f=f.get(u[y]);if(!f.has(w)||f.get(w)!==void 0&&!((g=(h=f.get(w))==null?void 0:h.deref)!=null&&g.call(h))){f.set(w,void 0);const y=k(Reflect.construct(s,u,t));f.set(w,new WeakRef(y));const I=F(y);c.register(y,{args:u,token:I},I)}return(A=(v=f.get(w))==null?void 0:v.deref)==null?void 0:A.call(v)}});return _.set(e,r),x.add(r),_.get(e);function t(){}}function T(e,n){if(n.length===0)return e.delete(w);const[o,...c]=n,r=e.get(o);if(!(r instanceof Map&&(T(r,c),r.size>0)))return e.delete(o)}function U(e){const n=k(e),o=F(n);return{register(c){o&&P.set(o,c)},unregister(){o&&P.delete(o)}}}function F(e){return S.has(e)||S.set(e,{}),S.get(e)}const q=Object.create(null);function D(e,n){const o=z(e),c=n?o(...n):q;return C(c)}function C(e){const[,n]=b.useReducer(o=>(o+1)%100,0);return b.useEffect(()=>(n(),M(e,()=>n())),[e]),e}l.finalizationRegistry=U,l.provide=z,l.useInstance=C,l.useModel=D,l.watch=M,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e7w/easy-model",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"module": "./dist/index.es.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
"lint:styles": "stylelint ./**/*.{css,scss}",
|
|
71
71
|
"format:scripts": "prettier . --write",
|
|
72
72
|
"format:styles": "stylelint ./**/*.{css,scss} --fix",
|
|
73
|
-
"format": "npm run format:scripts && npm run format:styles"
|
|
74
|
-
"uninstall-husky": "npm uninstall husky --no-save && git config --unset core.hooksPath && npx rimraf .husky"
|
|
73
|
+
"format": "npm run format:scripts && npm run format:styles"
|
|
75
74
|
}
|
|
76
75
|
}
|