@e7w/easy-model 0.0.11 → 0.0.12
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 +26 -26
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/provide.ts +1 -1
package/dist/index.es.js
CHANGED
|
@@ -5,17 +5,17 @@ const H = [Promise, WeakMap, WeakSet, Map, Set];
|
|
|
5
5
|
function v(n) {
|
|
6
6
|
return H.some((t) => n instanceof t);
|
|
7
7
|
}
|
|
8
|
-
const g = /* @__PURE__ */ new WeakMap(),
|
|
9
|
-
function
|
|
10
|
-
if (n =
|
|
8
|
+
const g = /* @__PURE__ */ new WeakMap(), j = Symbol("origin");
|
|
9
|
+
function o(n) {
|
|
10
|
+
if (n = c(n), v(n))
|
|
11
11
|
return n;
|
|
12
12
|
if (g.has(n))
|
|
13
13
|
return g.get(n);
|
|
14
14
|
const t = new Proxy(n, new T(n));
|
|
15
15
|
return g.set(n, t), t;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
return n && (n[
|
|
17
|
+
function c(n) {
|
|
18
|
+
return n && (n[j] || n);
|
|
19
19
|
}
|
|
20
20
|
class T {
|
|
21
21
|
constructor(t) {
|
|
@@ -24,17 +24,17 @@ class T {
|
|
|
24
24
|
this.obj = t;
|
|
25
25
|
}
|
|
26
26
|
get(t, e, r) {
|
|
27
|
-
if (e ===
|
|
27
|
+
if (e === j)
|
|
28
28
|
return this.obj;
|
|
29
29
|
if (v(t))
|
|
30
|
-
return Reflect.get(
|
|
31
|
-
let s =
|
|
32
|
-
return typeof s == "function" ? this.cachedFns[e] || (this.cachedFns[e] = s.bind(
|
|
30
|
+
return Reflect.get(c(t), e);
|
|
31
|
+
let s = E(t, e) || Reflect.get(t, e, r);
|
|
32
|
+
return typeof s == "function" ? this.cachedFns[e] || (this.cachedFns[e] = s.bind(o(t))) : (typeof s == "object" && (s = o(s), _(s, this.getTrigger(e))), s);
|
|
33
33
|
}
|
|
34
34
|
set(t, e, r, s) {
|
|
35
|
-
if (r && (r =
|
|
35
|
+
if (r && (r = c(r)), r === c(Reflect.get(t, e)))
|
|
36
36
|
return !0;
|
|
37
|
-
const i =
|
|
37
|
+
const i = R(), u = Reflect.set(t, e, r, s);
|
|
38
38
|
return y(this.obj, [e]), M(i), u;
|
|
39
39
|
}
|
|
40
40
|
getTrigger(t) {
|
|
@@ -52,17 +52,17 @@ const l = [
|
|
|
52
52
|
"sort",
|
|
53
53
|
"reverse"
|
|
54
54
|
], x = ["includes", "indexOf", "lastIndexOf"], W = ["forEach", "map"];
|
|
55
|
-
function
|
|
55
|
+
function E(n, t) {
|
|
56
56
|
return t === "hasOwnProperty" ? function(e) {
|
|
57
|
-
return
|
|
57
|
+
return c(this).hasOwnProperty(e);
|
|
58
58
|
} : Array.isArray(n) && typeof l[t] == "function" ? W.includes(t) ? n[t] : function(...e) {
|
|
59
|
-
const r = l[t].apply(
|
|
60
|
-
return x.includes(t) && (r === -1 || r === !1) ? l[t].apply(
|
|
59
|
+
const r = l[t].apply(c(this), e);
|
|
60
|
+
return x.includes(t) && (r === -1 || r === !1) ? l[t].apply(c(this), ...e.map(c)) : (l.includes(t) && y(this, [t]), r);
|
|
61
61
|
} : null;
|
|
62
62
|
}
|
|
63
63
|
const p = /* @__PURE__ */ new WeakMap();
|
|
64
64
|
function m(n) {
|
|
65
|
-
return n =
|
|
65
|
+
return n = c(n), p.has(n) || p.set(n, /* @__PURE__ */ new Set()), p.get(n);
|
|
66
66
|
}
|
|
67
67
|
function _(n, t) {
|
|
68
68
|
m(n).add(t);
|
|
@@ -87,7 +87,7 @@ function I(n) {
|
|
|
87
87
|
t.removeEventListener(b, n), n();
|
|
88
88
|
}), t.dispatchEvent(e);
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function R() {
|
|
91
91
|
return d ? null : d = Symbol();
|
|
92
92
|
}
|
|
93
93
|
function M(n) {
|
|
@@ -100,7 +100,7 @@ function L(n) {
|
|
|
100
100
|
}
|
|
101
101
|
function U(n, t, e) {
|
|
102
102
|
const r = e ? n(...e) : Object.create(n.prototype);
|
|
103
|
-
return
|
|
103
|
+
return o(Object.assign(r, t));
|
|
104
104
|
}
|
|
105
105
|
const O = class {
|
|
106
106
|
constructor(t) {
|
|
@@ -132,12 +132,12 @@ const O = class {
|
|
|
132
132
|
this.filterArgs(e),
|
|
133
133
|
r === this.Ctor ? this.fakeCtor : r
|
|
134
134
|
);
|
|
135
|
-
return h !== r ?
|
|
135
|
+
return h !== r ? o(s) : s;
|
|
136
136
|
}
|
|
137
137
|
set(t, e, r, s) {
|
|
138
|
-
if (r && (r =
|
|
138
|
+
if (r && (r = c(r)), r === c(Reflect.get(t, e)))
|
|
139
139
|
return !0;
|
|
140
|
-
const i =
|
|
140
|
+
const i = R(), u = Reflect.set(t, e, r, s);
|
|
141
141
|
return this.caches.forEach((w) => {
|
|
142
142
|
const S = w.deref();
|
|
143
143
|
S && y(S, []);
|
|
@@ -150,15 +150,15 @@ const O = class {
|
|
|
150
150
|
))
|
|
151
151
|
continue;
|
|
152
152
|
const r = this.caches.get(e);
|
|
153
|
-
return r.deref() ?
|
|
153
|
+
return r.deref() ? o(r.deref()) : (this.caches.delete(e), null);
|
|
154
154
|
}
|
|
155
155
|
return null;
|
|
156
156
|
}
|
|
157
157
|
register(t, e) {
|
|
158
|
-
return this.caches.set(t, new WeakRef(e)),
|
|
158
|
+
return this.caches.set(t, new WeakRef(e)), o(e);
|
|
159
159
|
}
|
|
160
160
|
isShallowEqualObj(t, e) {
|
|
161
|
-
const r = Object.keys(t), s =
|
|
161
|
+
const r = Object.keys(t), s = Object.keys(e);
|
|
162
162
|
return r.length === s.length && r.every((i) => t[i] === e[i]);
|
|
163
163
|
}
|
|
164
164
|
filterArgs(t) {
|
|
@@ -168,12 +168,12 @@ const O = class {
|
|
|
168
168
|
let a = O;
|
|
169
169
|
f(a, "prototypeHandlers", {
|
|
170
170
|
get(t, e, r) {
|
|
171
|
-
const s =
|
|
171
|
+
const s = E(t, e);
|
|
172
172
|
if (s)
|
|
173
173
|
return s;
|
|
174
174
|
const i = Reflect.get(t, e, r);
|
|
175
175
|
return typeof e == "symbol" || ["constructor", "__proto__"].includes(e) || typeof i != "function" ? i : function(...u) {
|
|
176
|
-
return i.apply(
|
|
176
|
+
return i.apply(o(this), u);
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
});
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o["@e7w/easy-model"]={}))})(this,function(o){"use strict";var L=Object.defineProperty;var U=(o,c,u)=>c in o?L(o,c,{enumerable:!0,configurable:!0,writable:!0,value:u}):o[c]=u;var h=(o,c,u)=>(U(o,typeof c!="symbol"?c+"":c,u),u);const c=[Promise,WeakMap,WeakSet,Map,Set];function u(n){return c.some(e=>n instanceof e)}const m=new WeakMap,E=Symbol("origin");function l(n){if(n=f(n),u(n))return n;if(m.has(n))return m.get(n);const e=new Proxy(n,new A(n));return m.set(n,e),e}function f(n){return n&&(n[E]||n)}class A{constructor(e){h(this,"triggers",{});h(this,"cachedFns",{});this.obj=e}get(e,t,s){if(t===E)return this.obj;if(u(e))return Reflect.get(f(e),t);let r=M(e,t)||Reflect.get(e,t,s);return typeof r=="function"?this.cachedFns[t]||(this.cachedFns[t]=r.bind(l(e))):(typeof r=="object"&&(r=l(r),
|
|
1
|
+
(function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o["@e7w/easy-model"]={}))})(this,function(o){"use strict";var L=Object.defineProperty;var U=(o,c,u)=>c in o?L(o,c,{enumerable:!0,configurable:!0,writable:!0,value:u}):o[c]=u;var h=(o,c,u)=>(U(o,typeof c!="symbol"?c+"":c,u),u);const c=[Promise,WeakMap,WeakSet,Map,Set];function u(n){return c.some(e=>n instanceof e)}const m=new WeakMap,E=Symbol("origin");function l(n){if(n=f(n),u(n))return n;if(m.has(n))return m.get(n);const e=new Proxy(n,new A(n));return m.set(n,e),e}function f(n){return n&&(n[E]||n)}class A{constructor(e){h(this,"triggers",{});h(this,"cachedFns",{});this.obj=e}get(e,t,s){if(t===E)return this.obj;if(u(e))return Reflect.get(f(e),t);let r=M(e,t)||Reflect.get(e,t,s);return typeof r=="function"?this.cachedFns[t]||(this.cachedFns[t]=r.bind(l(e))):(typeof r=="object"&&(r=l(r),_(r,this.getTrigger(t))),r)}set(e,t,s,r){if(s&&(s=f(s)),s===f(Reflect.get(e,t)))return!0;const i=R(),a=Reflect.set(e,t,s,r);return b(this.obj,[t]),w(i),a}getTrigger(e){return e in this.triggers||(this.triggers[e]=t=>b(this.obj,[e,...t])),this.triggers[e]}}const k=new Set;let d=null;const y=["push","pop","shift","unshift","splice","sort","reverse"],H=["includes","indexOf","lastIndexOf"],W=["forEach","map"];function M(n,e){return e==="hasOwnProperty"?function(t){return f(this).hasOwnProperty(t)}:Array.isArray(n)&&typeof y[e]=="function"?W.includes(e)?n[e]:function(...t){const s=y[e].apply(f(this),t);return H.includes(e)&&(s===-1||s===!1)?y[e].apply(f(this),...t.map(f)):(y.includes(e)&&b(this,[e]),s)}:null}const S=new WeakMap;function O(n){return n=f(n),S.has(n)||S.set(n,new Set),S.get(n)}function _(n,e){O(n).add(e)}function x(n,e){const t=r=>{const i=k.has(e);k.add(e),i||I(()=>e(r)),_(n,t)},s=()=>{O(n).delete(t)};return _(n,t),s}function b(n,e){const t=O(n),s=[...t];t.clear(),s.forEach(r=>r(e))}const v="__easy_model_event__";function I(n){const e=new EventTarget,t=new Event(v);e.addEventListener(v,()=>{e.removeEventListener(v,n),n()}),e.dispatchEvent(t)}function R(){return d?null:d=Symbol()}function w(n){d===n&&(d=null,k.clear())}let p=null;const T=Symbol("filterSymbol");function P(n){return new Proxy(n,new g(n))}function F(n,e,t){const s=t?n(...t):Object.create(n.prototype);return l(Object.assign(s,e))}const j=class{constructor(e){h(this,"fakeCtor");h(this,"caches",new Map);this.Ctor=e;const t=function(){};t.prototype=new Proxy({constructor:e,__proto__:e.prototype},j.prototypeHandlers),this.fakeCtor=t}apply(e,t,s){const r=p;p=this.fakeCtor;const i=this.getInstance(s)||this.register(s,Reflect.construct(this.Ctor,this.filterArgs(s),this.fakeCtor));return p=r,i}construct(e,t,s){const r=Reflect.construct(e,this.filterArgs(t),s===this.Ctor?this.fakeCtor:s);return p!==s?l(r):r}set(e,t,s,r){if(s&&(s=f(s)),s===f(Reflect.get(e,t)))return!0;const i=R(),a=Reflect.set(e,t,s,r);return this.caches.forEach(q=>{const C=q.deref();C&&b(C,[])}),w(i),a}getInstance(e){for(const t of this.caches.keys()){if(t.length!==e.length||!t.every((r,i)=>r===e[i]?!0:typeof r=="object"&&typeof e[i]=="object"?this.isShallowEqualObj(r,e[i]):!1))continue;const s=this.caches.get(t);return s.deref()?l(s.deref()):(this.caches.delete(t),null)}return null}register(e,t){return this.caches.set(e,new WeakRef(t)),l(t)}isShallowEqualObj(e,t){const s=Object.keys(e),r=Object.keys(t);return s.length===r.length&&s.every(i=>e[i]===t[i])}filterArgs(e){return e.filter(t=>t!==T)}};let g=j;h(g,"prototypeHandlers",{get(e,t,s){const r=M(e,t);if(r)return r;const i=Reflect.get(e,t,s);return typeof t=="symbol"||["constructor","__proto__"].includes(t)||typeof i!="function"?i:function(...a){return i.apply(l(this),a)}}}),o.extend=F,o.filterSymbol=T,o.provide=P,o.subscribe=x,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/provide.ts
CHANGED
|
@@ -163,7 +163,7 @@ class Provider<T extends Ctor> implements ProxyHandler<T> {
|
|
|
163
163
|
|
|
164
164
|
private isShallowEqualObj(objectA: Obj, objectB: Obj): Boolean {
|
|
165
165
|
const kOfA = Object.keys(objectA);
|
|
166
|
-
const kOfB =
|
|
166
|
+
const kOfB = Object.keys(objectB);
|
|
167
167
|
return (
|
|
168
168
|
kOfA.length === kOfB.length &&
|
|
169
169
|
kOfA.every((key) => objectA[key] === objectB[key])
|