phecda-web 2.0.0 → 2.0.1

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/README.md CHANGED
@@ -4,4 +4,4 @@ Fulfill `phecda-core` standard (`Storage/Watcher`);
4
4
 
5
5
  Work for `phecda-vue`/`phecda-react`
6
6
 
7
- using `Proxy`
7
+ Using `Proxy` and `emitDecoratorMetadata`
package/dist/index.d.ts CHANGED
@@ -16,11 +16,11 @@ declare function defaultWebInject(): void;
16
16
  declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
17
17
  declare function bindMethod(instance: any): any;
18
18
  declare class WebPhecda {
19
- protected proxyFn: Function;
19
+ protected parseModule: <Instance = any>(instance: Instance) => Instance;
20
20
  origin: Record<string, any>;
21
21
  state: Record<string | symbol, any>;
22
22
  modelMap: WeakMap<object, any>;
23
- constructor(proxyFn: Function);
23
+ constructor(parseModule: <Instance = any>(instance: Instance) => Instance);
24
24
  init<Model extends Construct>(model: Model): InstanceType<Model>;
25
25
  patch<Model extends Construct>(model: Model, data: DeepPartial<InstanceType<Model>>): void;
26
26
  wait(...modelOrTag: (Construct | PropertyKey)[]): Promise<any[]>;
package/dist/index.js CHANGED
@@ -122,32 +122,37 @@ function getParamtypes(Model, key) {
122
122
  return Reflect.getMetadata("design:paramtypes", Model, key);
123
123
  }
124
124
  __name(getParamtypes, "getParamtypes");
125
+ var bindCache = /* @__PURE__ */ new WeakMap();
125
126
  function bindMethod(instance) {
126
- const cache = /* @__PURE__ */ new WeakMap();
127
- return new Proxy(instance, {
128
- get(target, p) {
129
- if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
130
- if (!cache.has(target[p]))
131
- cache.set(target[p], target[p].bind(target));
132
- return cache.get(target[p]);
127
+ if (!bindCache.has(instance)) {
128
+ const cache = /* @__PURE__ */ new WeakMap();
129
+ bindCache.set(instance, new Proxy(instance, {
130
+ get(target, p) {
131
+ if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
132
+ if (!cache.has(target[p]))
133
+ cache.set(target[p], target[p].bind(target));
134
+ return cache.get(target[p]);
135
+ }
136
+ return target[p];
133
137
  }
134
- return target[p];
135
- }
136
- });
138
+ }));
139
+ }
140
+ return bindCache.get(instance);
137
141
  }
138
142
  __name(bindMethod, "bindMethod");
139
143
  var WebPhecda = class {
140
- proxyFn;
144
+ parseModule;
141
145
  origin;
142
146
  state;
143
147
  modelMap;
144
- constructor(proxyFn) {
145
- this.proxyFn = proxyFn;
148
+ constructor(parseModule) {
149
+ this.parseModule = parseModule;
146
150
  this.origin = {};
147
151
  this.state = {};
148
152
  this.modelMap = /* @__PURE__ */ new WeakMap();
149
153
  defaultWebInject();
150
154
  }
155
+ // Initialize a module that has not been created yet, and return it directly if it is cached.
151
156
  init(model) {
152
157
  const tag = (0, import_phecda_core2.getTag)(model);
153
158
  const initModel = /* @__PURE__ */ __name(() => {
@@ -157,9 +162,9 @@ var WebPhecda = class {
157
162
  const paramtypesInstances = [];
158
163
  for (const i in paramtypes)
159
164
  paramtypesInstances[i] = this.init(paramtypes[i]);
160
- instance2 = this.proxyFn(new model(...paramtypesInstances));
165
+ instance2 = this.parseModule(new model(...paramtypesInstances));
161
166
  } else {
162
- instance2 = this.proxyFn(new model());
167
+ instance2 = this.parseModule(new model());
163
168
  }
164
169
  if (tag in this.origin) {
165
170
  Object.assign(instance2, this.origin[tag]);
@@ -167,7 +172,7 @@ var WebPhecda = class {
167
172
  }
168
173
  if (typeof window !== "undefined")
169
174
  instance2._promise = (0, import_phecda_core2.invokeHandler)("init", instance2);
170
- return bindMethod(instance2);
175
+ return instance2;
171
176
  }, "initModel");
172
177
  const { state, modelMap: map } = this;
173
178
  if ((0, import_phecda_core2.get)(model.prototype, "isolate"))
package/dist/index.mjs CHANGED
@@ -84,32 +84,37 @@ function getParamtypes(Model, key) {
84
84
  return Reflect.getMetadata("design:paramtypes", Model, key);
85
85
  }
86
86
  __name(getParamtypes, "getParamtypes");
87
+ var bindCache = /* @__PURE__ */ new WeakMap();
87
88
  function bindMethod(instance) {
88
- const cache = /* @__PURE__ */ new WeakMap();
89
- return new Proxy(instance, {
90
- get(target, p) {
91
- if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
92
- if (!cache.has(target[p]))
93
- cache.set(target[p], target[p].bind(target));
94
- return cache.get(target[p]);
89
+ if (!bindCache.has(instance)) {
90
+ const cache = /* @__PURE__ */ new WeakMap();
91
+ bindCache.set(instance, new Proxy(instance, {
92
+ get(target, p) {
93
+ if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
94
+ if (!cache.has(target[p]))
95
+ cache.set(target[p], target[p].bind(target));
96
+ return cache.get(target[p]);
97
+ }
98
+ return target[p];
95
99
  }
96
- return target[p];
97
- }
98
- });
100
+ }));
101
+ }
102
+ return bindCache.get(instance);
99
103
  }
100
104
  __name(bindMethod, "bindMethod");
101
105
  var WebPhecda = class {
102
- proxyFn;
106
+ parseModule;
103
107
  origin;
104
108
  state;
105
109
  modelMap;
106
- constructor(proxyFn) {
107
- this.proxyFn = proxyFn;
110
+ constructor(parseModule) {
111
+ this.parseModule = parseModule;
108
112
  this.origin = {};
109
113
  this.state = {};
110
114
  this.modelMap = /* @__PURE__ */ new WeakMap();
111
115
  defaultWebInject();
112
116
  }
117
+ // Initialize a module that has not been created yet, and return it directly if it is cached.
113
118
  init(model) {
114
119
  const tag = getTag(model);
115
120
  const initModel = /* @__PURE__ */ __name(() => {
@@ -119,9 +124,9 @@ var WebPhecda = class {
119
124
  const paramtypesInstances = [];
120
125
  for (const i in paramtypes)
121
126
  paramtypesInstances[i] = this.init(paramtypes[i]);
122
- instance2 = this.proxyFn(new model(...paramtypesInstances));
127
+ instance2 = this.parseModule(new model(...paramtypesInstances));
123
128
  } else {
124
- instance2 = this.proxyFn(new model());
129
+ instance2 = this.parseModule(new model());
125
130
  }
126
131
  if (tag in this.origin) {
127
132
  Object.assign(instance2, this.origin[tag]);
@@ -129,7 +134,7 @@ var WebPhecda = class {
129
134
  }
130
135
  if (typeof window !== "undefined")
131
136
  instance2._promise = invokeHandler("init", instance2);
132
- return bindMethod(instance2);
137
+ return instance2;
133
138
  }, "initModel");
134
139
  const { state, modelMap: map } = this;
135
140
  if (get(model.prototype, "isolate"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-web",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "using proxy, provide phecda function to web app",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",