@e7w/easy-model 0.0.2 → 0.0.3
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 +15 -14
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/observe.ts +1 -0
- package/src/provide.ts +1 -0
package/dist/index.es.js
CHANGED
|
@@ -3,12 +3,12 @@ var _ = (n, t, e) => t in n ? j(n, t, { enumerable: !0, configurable: !0, writab
|
|
|
3
3
|
var i = (n, t, e) => (_(n, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
4
|
const h = /* @__PURE__ */ new WeakMap(), k = Symbol("origin");
|
|
5
5
|
function o(n) {
|
|
6
|
-
if (n =
|
|
6
|
+
if (n = u(n), h.has(n))
|
|
7
7
|
return h.get(n);
|
|
8
8
|
const t = new Proxy(n, new C(n));
|
|
9
9
|
return h.set(n, t), t;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function u(n) {
|
|
12
12
|
return n[k] || n;
|
|
13
13
|
}
|
|
14
14
|
class C {
|
|
@@ -20,10 +20,11 @@ class C {
|
|
|
20
20
|
get(t, e, s) {
|
|
21
21
|
if (e === k)
|
|
22
22
|
return this.obj;
|
|
23
|
-
let r =
|
|
23
|
+
let r = O(t, e) || Reflect.get(t, e, s);
|
|
24
24
|
return typeof r == "function" ? this.cachedFns[e] || (this.cachedFns[e] = r.bind(o(t))) : (typeof r == "object" && (r = o(r), y(r, this.getTrigger(e))), r);
|
|
25
25
|
}
|
|
26
26
|
set(t, e, s, r) {
|
|
27
|
+
s && (s = u(s));
|
|
27
28
|
const c = Reflect.set(t, e, s, r);
|
|
28
29
|
return d(this.obj, [e]), c;
|
|
29
30
|
}
|
|
@@ -32,17 +33,17 @@ class C {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
const l = ["push", "pop", "shift", "unshift", "splice"];
|
|
35
|
-
function
|
|
36
|
+
function O(n, t) {
|
|
36
37
|
return t === "hasOwnProperty" ? function(e) {
|
|
37
|
-
return
|
|
38
|
+
return u(this).hasOwnProperty(e);
|
|
38
39
|
} : Array.isArray(n) && typeof l[t] == "function" ? function(...e) {
|
|
39
|
-
const s = l[t].apply(
|
|
40
|
+
const s = l[t].apply(u(this), e);
|
|
40
41
|
return l.includes(t) && d(this, [t]), s;
|
|
41
42
|
} : null;
|
|
42
43
|
}
|
|
43
44
|
const a = /* @__PURE__ */ new WeakMap();
|
|
44
45
|
function b(n) {
|
|
45
|
-
return n =
|
|
46
|
+
return n = u(n), a.has(n) || a.set(n, /* @__PURE__ */ new Set()), a.get(n);
|
|
46
47
|
}
|
|
47
48
|
function y(n, t) {
|
|
48
49
|
b(n).add(t);
|
|
@@ -61,7 +62,7 @@ function d(n, t) {
|
|
|
61
62
|
}
|
|
62
63
|
let p = null;
|
|
63
64
|
function M(n) {
|
|
64
|
-
return new Proxy(n, new
|
|
65
|
+
return new Proxy(n, new f(n));
|
|
65
66
|
}
|
|
66
67
|
function S(n, t, e) {
|
|
67
68
|
const s = e ? n(...e) : Object.create(n.prototype);
|
|
@@ -100,7 +101,7 @@ const g = class {
|
|
|
100
101
|
}
|
|
101
102
|
getInstance(t) {
|
|
102
103
|
for (const e of this.caches.keys()) {
|
|
103
|
-
if (!e.every(
|
|
104
|
+
if (e.length !== t.length || !e.every(
|
|
104
105
|
(r, c) => r === t[c] ? !0 : typeof r == "object" && typeof t[c] == "object" ? this.isShallowEqualObj(r, t[c]) : !1
|
|
105
106
|
))
|
|
106
107
|
continue;
|
|
@@ -117,15 +118,15 @@ const g = class {
|
|
|
117
118
|
return s.length === r.length && s.every((c) => t[c] === e[c]);
|
|
118
119
|
}
|
|
119
120
|
};
|
|
120
|
-
let
|
|
121
|
-
i(
|
|
121
|
+
let f = g;
|
|
122
|
+
i(f, "prototypeHandlers", {
|
|
122
123
|
get(t, e, s) {
|
|
123
|
-
const r =
|
|
124
|
+
const r = O(t, e);
|
|
124
125
|
if (r)
|
|
125
126
|
return r;
|
|
126
127
|
const c = Reflect.get(t, e, s);
|
|
127
|
-
return typeof e == "symbol" || ["constructor", "__proto__"].includes(e) || typeof c != "function" ? c : function(...
|
|
128
|
-
return c.apply(o(this),
|
|
128
|
+
return typeof e == "symbol" || ["constructor", "__proto__"].includes(e) || typeof c != "function" ? c : function(...w) {
|
|
129
|
+
return c.apply(o(this), w);
|
|
129
130
|
};
|
|
130
131
|
}
|
|
131
132
|
});
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(i=typeof globalThis<"u"?globalThis:i||self,o(i["@e7w/easy-model"]={}))})(this,function(i){"use strict";var M=Object.defineProperty;var R=(i,o,u)=>o in i?M(i,o,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[o]=u;var h=(i,o,u)=>(R(i,typeof o!="symbol"?o+"":o,u),u);const o=new WeakMap,u=Symbol("origin");function f(n){if(n=l(n),o.has(n))return o.get(n);const e=new Proxy(n,new
|
|
1
|
+
(function(i,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(i=typeof globalThis<"u"?globalThis:i||self,o(i["@e7w/easy-model"]={}))})(this,function(i){"use strict";var M=Object.defineProperty;var R=(i,o,u)=>o in i?M(i,o,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[o]=u;var h=(i,o,u)=>(R(i,typeof o!="symbol"?o+"":o,u),u);const o=new WeakMap,u=Symbol("origin");function f(n){if(n=l(n),o.has(n))return o.get(n);const e=new Proxy(n,new w(n));return o.set(n,e),e}function l(n){return n[u]||n}class w{constructor(e){h(this,"triggers",{});h(this,"cachedFns",{});this.obj=e}get(e,t,s){if(t===u)return this.obj;let r=j(e,t)||Reflect.get(e,t,s);return typeof r=="function"?this.cachedFns[t]||(this.cachedFns[t]=r.bind(f(e))):(typeof r=="object"&&(r=f(r),b(r,this.getTrigger(t))),r)}set(e,t,s,r){s&&(s=l(s));const c=Reflect.set(e,t,s,r);return g(this.obj,[t]),c}getTrigger(e){return e in this.triggers||(this.triggers[e]=t=>g(this.obj,[e,...t])),this.triggers[e]}}const d=["push","pop","shift","unshift","splice"];function j(n,e){return e==="hasOwnProperty"?function(t){return l(this).hasOwnProperty(t)}:Array.isArray(n)&&typeof d[e]=="function"?function(...t){const s=d[e].apply(l(this),t);return d.includes(e)&&g(this,[e]),s}:null}const p=new WeakMap;function y(n){return n=l(n),p.has(n)||p.set(n,new Set),p.get(n)}function b(n,e){y(n).add(e)}function _(n,e){const t=r=>{e(r),b(n,t)},s=()=>{y(n).delete(t)};return b(n,t),s}function g(n,e){const t=y(n),s=[...t];return t.clear(),s.forEach(r=>r(e))}let k=null;function m(n){return new Proxy(n,new a(n))}function C(n,e,t){const s=t?n(...t):Object.create(n.prototype);return f(Object.assign(s,e))}const O=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},O.prototypeHandlers),this.fakeCtor=t}apply(e,t,s){k=this.fakeCtor;const r=this.getInstance(s)||this.register(s,Reflect.construct(this.Ctor,s,this.fakeCtor));return k=null,r}construct(e,t,s){const r=Reflect.construct(e,t,s===this.Ctor?this.fakeCtor:s);return k!==s?f(r):r}getInstance(e){for(const t of this.caches.keys()){if(t.length!==e.length||!t.every((r,c)=>r===e[c]?!0:typeof r=="object"&&typeof e[c]=="object"?this.isShallowEqualObj(r,e[c]):!1))continue;const s=this.caches.get(t);return s.deref()?f(s.deref()):(this.caches.delete(t),null)}return null}register(e,t){return this.caches.set(e,new WeakRef(t)),f(t)}isShallowEqualObj(e,t){const s=Object.keys(e),r=t.keys(t);return s.length===r.length&&s.every(c=>e[c]===t[c])}};let a=O;h(a,"prototypeHandlers",{get(e,t,s){const r=j(e,t);if(r)return r;const c=Reflect.get(e,t,s);return typeof t=="symbol"||["constructor","__proto__"].includes(t)||typeof c!="function"?c:function(...H){return c.apply(f(this),H)}}}),i.extend=C,i.provide=m,i.subscribe=_,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/observe.ts
CHANGED
|
@@ -45,6 +45,7 @@ class ObserveHandler<T extends Obj> implements ProxyHandler<T> {
|
|
|
45
45
|
newValue: any,
|
|
46
46
|
receiver: any
|
|
47
47
|
): boolean {
|
|
48
|
+
if (newValue) newValue = getOrigin(newValue);
|
|
48
49
|
const ret = Reflect.set(target, p, newValue, receiver);
|
|
49
50
|
trigger(this.obj, [p]);
|
|
50
51
|
return ret;
|
package/src/provide.ts
CHANGED
|
@@ -106,6 +106,7 @@ class Provider<T extends Ctor> implements ProxyHandler<T> {
|
|
|
106
106
|
private getInstance(args: ConstructorParameters<T>): InstanceType<T> | null {
|
|
107
107
|
for (const cachedArgs of this.caches.keys()) {
|
|
108
108
|
if (
|
|
109
|
+
cachedArgs.length !== args.length ||
|
|
109
110
|
!cachedArgs.every((arg, index) =>
|
|
110
111
|
arg === args[index]
|
|
111
112
|
? true
|