@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 CHANGED
@@ -1,81 +1,81 @@
1
- import { useRef as C, useReducer as A, useEffect as L } from "react";
2
- const _ = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), O = Symbol("origin");
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 v = ["includes", "indexOf", "lastIndexOf"], U = [Promise, RegExp, Date, WeakMap, WeakSet, Map, Set];
4
+ const _ = ["includes", "indexOf", "lastIndexOf"], T = [Promise, RegExp, Date, WeakMap, WeakSet, Map, Set];
5
5
  function w(e) {
6
- if (e = l(e), !e || U.some((c) => e instanceof c)) return e;
7
- if (_.has(e)) return _.get(e);
8
- const n = {}, r = {}, i = new Proxy(e, {
9
- get(c, t, s) {
10
- if (t === O) return c;
11
- let o = j(c, t);
12
- return o || (o = Reflect.get(c, t, s), typeof o == "function" ? (r[t] || (r[t] = o.bind(w(c))), o = r[t]) : typeof o == "object" && o !== null && (n[t] || (n[t] = R(o, x(e, t))), o = w(o)), o);
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(c, t, s, o) {
15
- let u = Reflect.get(c, t, o);
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(c, t, s, o);
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, x(e, t))), r[t] && delete r[t];
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(c, [t], u, s), d = y;
21
+ d = /* @__PURE__ */ new WeakSet(), W(i, [t], u, s), d = y;
22
22
  }
23
23
  return f;
24
24
  },
25
- deleteProperty(c, t) {
26
- let s = Reflect.get(c, t);
25
+ deleteProperty(i, t) {
26
+ let s = Reflect.get(i, t);
27
27
  s = l(s);
28
- const o = Reflect.deleteProperty(c, t);
29
- return o && (n[t] && (n[t](), delete n[t]), r[t] && delete r[t], W(c, [t], s, void 0)), o;
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 _.set(e, i), i;
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 r = p.get(e), i = Symbol();
37
- return r.set(i, n), function() {
38
- r.delete(i);
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 x(e, n) {
42
- return function(...r) {
43
- const [i, ...c] = r;
44
- W(e, [n, ...i], ...c);
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 r = p.get(e);
51
- if (!r) return;
52
- [...r.values()].forEach((c) => {
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, o), t.dispatchEvent(s);
55
- function o() {
56
- t.removeEventListener(s.type, o), c(...n);
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[O] ?? e;
61
+ return typeof e != "object" || e === null ? e : e[j] ?? e;
62
62
  }
63
- function j(e, n) {
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(r) {
68
- return Object.prototype.hasOwnProperty.call(l(this), r);
67
+ return function(o) {
68
+ return Object.prototype.hasOwnProperty.call(l(this), o);
69
69
  };
70
- if (Array.isArray(e) && v.includes(n))
71
- return function(...r) {
72
- const i = v[n].apply(l(this), r);
73
- return i === -1 || i === !1 ? v[n].apply(l(this), r.map(l)) : i;
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(), E = /* @__PURE__ */ new WeakSet(), z = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap();
77
- function D(e) {
78
- if (E.has(e))
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, o, u) {
90
- let f = j(s, o);
91
- return f || (f = Reflect.get(s, o, u), typeof o == "symbol" || ["constructor", "__proto__"].includes(o) || typeof f != "function") ? f : (n[o] || (n[o] = function(...y) {
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[o]);
93
+ }), n[r]);
94
94
  }
95
95
  }
96
96
  );
97
- const r = /* @__PURE__ */ new Map(), i = new FinalizationRegistry(
98
- ({ args: s, token: o }) => {
97
+ const o = /* @__PURE__ */ new Map(), c = new FinalizationRegistry(
98
+ ({ args: s, token: r }) => {
99
99
  var u;
100
- F(r, s), (u = m.get(o)) == null || u(), i.unregister(o);
100
+ F(o, s), (u = m.get(r)) == null || u(), c.unregister(r);
101
101
  }
102
- ), c = new Proxy(e, {
103
- apply(s, o, u) {
102
+ ), i = new Proxy(e, {
103
+ apply(s, r, u) {
104
104
  var y, P, k, S;
105
- let f = r;
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 M = {};
113
- z.set(a, M), i.register(a, { args: u, token: M }, M);
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, c), E.add(c), b.get(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 [r, ...i] = n, c = e.get(r);
125
- if (!(c instanceof Map && (F(c, i), c.size > 0)))
126
- return e.delete(r);
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 q(e) {
129
- const n = w(e), r = z.get(n);
128
+ function g(e) {
129
+ const n = w(e), o = C(n);
130
130
  return {
131
- register(i) {
132
- r && m.set(r, i);
131
+ register(c) {
132
+ o && m.set(o, c);
133
133
  },
134
134
  unregister() {
135
- r && m.delete(r);
135
+ o && m.delete(o);
136
136
  }
137
137
  };
138
138
  }
139
- const G = /* @__PURE__ */ Object.create(null);
140
- function B(e, n) {
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
- function I(e) {
145
- const n = C(null);
146
- n.current !== e && (n.current = e);
147
- const [, r] = A((i) => (i + 1) % 100, 0);
148
- return L(() => R(n.current, () => {
149
- r();
150
- }), [n.current]), n.current;
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
- q as finalizationRegistry,
154
- D as provide,
155
- I as useInstance,
156
- B as useModel,
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,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],w):(l=typeof globalThis<"u"?globalThis:l||self,w(l["@e7w/easy-model"]={},l.React))})(this,function(l,w){"use strict";const R=new WeakMap,k=new WeakMap,O=Symbol("origin");let d=null;const m=["includes","indexOf","lastIndexOf"],L=[Promise,RegExp,Date,WeakMap,WeakSet,Map,Set];function p(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={},s=new Proxy(e,{get(r,t,c){if(t===O)return r;let i=E(r,t);return i||(i=Reflect.get(r,t,c),typeof i=="function"?(o[t]||(o[t]=i.bind(p(r))),i=o[t]):typeof i=="object"&&i!==null&&(n[t]||(n[t]=M(i,j(e,t))),i=p(i)),i)},set(r,t,c,i){let u=Reflect.get(r,t,i);if(u=a(u),c=a(c),u===c)return!0;const f=Reflect.set(r,t,c,i);if(f){n[t]&&(n[t](),delete n[t]),typeof c=="object"&&c!==null&&(n[t]=M(c,j(e,t))),o[t]&&delete o[t];const h=d;d=new WeakSet,W(r,[t],u,c),d=h}return f},deleteProperty(r,t){let c=Reflect.get(r,t);c=a(c);const i=Reflect.deleteProperty(r,t);return i&&(n[t]&&(n[t](),delete n[t]),o[t]&&delete o[t],W(r,[t],c,void 0)),i}});return R.set(e,s),s}function M(e,n){e=a(e),k.has(e)||k.set(e,new Map);const o=k.get(e),s=Symbol();return o.set(s,n),function(){o.delete(s)}}function j(e,n){return function(...o){const[s,...r]=o;W(e,[n,...s],...r)}}function W(e,...n){if(e=a(e),d!=null&&d.has(e))return;d==null||d.add(e);const o=k.get(e);if(!o)return;[...o.values()].forEach(r=>{const t=new EventTarget,c=new Event("__trigger__");t.addEventListener(c.type,i),t.dispatchEvent(c);function i(){t.removeEventListener(c.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)&&m.includes(n))return function(...o){const s=m[n].apply(a(this),o);return s===-1||s===!1?m[n].apply(a(this),o.map(a)):s}}const b=Symbol("instance"),_=new WeakMap,x=new WeakSet,z=new WeakMap,S=new WeakMap;function F(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(c,i,u){let f=E(c,i);return f||(f=Reflect.get(c,i,u),typeof i=="symbol"||["constructor","__proto__"].includes(i)||typeof f!="function")?f:(n[i]||(n[i]=function(...h){return f.apply(p(this),h)}),n[i])}});const o=new Map,s=new FinalizationRegistry(({args:c,token:i})=>{var u;T(o,c),(u=S.get(i))==null||u(),s.unregister(i)}),r=new Proxy(e,{apply(c,i,u){var h,A,v,I;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(b)||f.get(b)!==void 0&&!((A=(h=f.get(b))==null?void 0:h.deref)!=null&&A.call(h))){f.set(b,void 0);const y=p(Reflect.construct(c,u,t));f.set(b,new WeakRef(y));const P={};z.set(y,P),s.register(y,{args:u,token:P},P)}return(I=(v=f.get(b))==null?void 0:v.deref)==null?void 0:I.call(v)}});return _.set(e,r),x.add(r),_.get(e);function t(){}}function T(e,n){if(n.length===0)return e.delete(b);const[o,...s]=n,r=e.get(o);if(!(r instanceof Map&&(T(r,s),r.size>0)))return e.delete(o)}function U(e){const n=p(e),o=z.get(n);return{register(s){o&&S.set(o,s)},unregister(){o&&S.delete(o)}}}const g=Object.create(null);function q(e,n){const o=F(e),s=n?o(...n):g;return C(s)}function C(e){const n=w.useRef(null);n.current!==e&&(n.current=e);const[,o]=w.useReducer(s=>(s+1)%100,0);return w.useEffect(()=>M(n.current,()=>{o()}),[n.current]),n.current}l.finalizationRegistry=U,l.provide=F,l.useInstance=C,l.useModel=q,l.watch=M,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
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",
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
  }