phecda-vue 2.1.1 → 2.1.2

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.d.ts CHANGED
@@ -10,6 +10,13 @@ type ReplaceInstanceValues<I> = {
10
10
  type SchemaToObj<S> = {
11
11
  [P in keyof S]: S[P] extends object ? SchemaToObj<S[P]> : (S[P] extends string ? any : S[P]);
12
12
  };
13
+ interface PhecdaInstance {
14
+ useOMap: Map<any, any>;
15
+ useVMap: WeakMap<any, any>;
16
+ useRMap: WeakMap<any, any>;
17
+ fnMap: WeakMap<any, any>;
18
+ computedMap: WeakMap<any, any>;
19
+ }
13
20
  interface PhecdaEmitter {
14
21
  on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
15
22
  off<N extends keyof Events>(eventName: N, cb?: (args: Events[N]) => void): void;
@@ -23,13 +30,6 @@ declare const interval: any;
23
30
  declare function createPhecda(symbol?: string): vue.Raw<{
24
31
  install(app: App): void;
25
32
  }>;
26
- interface PhecdaInstance {
27
- useVMap: WeakMap<any, any>;
28
- useOMap: Map<any, any>;
29
- useRMap: WeakMap<any, any>;
30
- fnMap: WeakMap<any, any>;
31
- computedMap: WeakMap<any, any>;
32
- }
33
33
  declare function setActivePhecda(phecda: PhecdaInstance): void;
34
34
  declare function getActivePhecda(): PhecdaInstance;
35
35
  declare function getReactiveMap(symbol: string): Map<string, any> | null;
@@ -44,7 +44,7 @@ declare function usePatch<T extends new (...args: any) => any>(Model: T, Data: _
44
44
  declare function useR<T extends new (...args: any) => any>(Model: T): UnwrapNestedRefs<InstanceType<T>>;
45
45
  declare function useV<T extends new (...args: any) => any>(Model: T): ReplaceInstanceValues<InstanceType<T>>;
46
46
  declare function useEvent<Key extends keyof Events>(eventName: Key, cb: Handler<Events[Key]>): () => void;
47
- declare function initialize<M extends new (...args: any) => any>(Model: M): InstanceType<M> | void;
47
+ declare function initialize<M extends new (...args: any) => any>(Model: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
48
48
 
49
49
  declare const RE: RegExp;
50
50
  declare function createFilter<Data extends Record<string, any>>(initState?: Object, option?: {
@@ -82,4 +82,4 @@ declare class PV {
82
82
  off<Key extends keyof Events>(type: Key, handler?: (arg: Events[Key]) => void): void;
83
83
  }
84
84
 
85
- export { PV, PhecdaEmitter, RE, ReplaceInstanceValues, SchemaToObj, createDialog, createFilter, createLayer, createPhecda, emitter, getActivePhecda, getReactiveMap, initialize, interval, phecdaSymbol, setActivePhecda, useEvent, useO, usePatch, useR, useRaw, useV };
85
+ export { PV, PhecdaEmitter, PhecdaInstance, RE, ReplaceInstanceValues, SchemaToObj, createDialog, createFilter, createLayer, createPhecda, emitter, getActivePhecda, getReactiveMap, initialize, interval, phecdaSymbol, setActivePhecda, useEvent, useO, usePatch, useR, useRaw, useV };
package/dist/index.js CHANGED
@@ -248,18 +248,15 @@ function useRaw(Model) {
248
248
  }
249
249
  __name(useRaw, "useRaw");
250
250
  function usePatch(Model, Data) {
251
- useO(Model);
252
- const { useOMap } = getActivePhecda();
253
- const target = useOMap.get(Model);
254
- mergeReactiveObjects(target, Data);
251
+ const instance = useO(Model);
252
+ mergeReactiveObjects(instance, Data);
255
253
  }
256
254
  __name(usePatch, "usePatch");
257
255
  function useR(Model) {
258
- useO(Model);
259
- const { useRMap, useOMap, fnMap } = getActivePhecda();
260
- if (useRMap.has(Model))
261
- return useRMap.get(Model);
262
- const instance = useOMap.get(Model);
256
+ const { useRMap, fnMap } = getActivePhecda();
257
+ const instance = useO(Model);
258
+ if (useRMap.has(instance))
259
+ return useRMap.get(instance);
263
260
  const proxy = new Proxy(instance, {
264
261
  get(target, key) {
265
262
  if (typeof target[key] === "function") {
@@ -279,17 +276,16 @@ function useR(Model) {
279
276
  return true;
280
277
  }
281
278
  });
282
- useRMap.set(Model, proxy);
279
+ useRMap.set(instance, proxy);
283
280
  return proxy;
284
281
  }
285
282
  __name(useR, "useR");
286
283
  function useV(Model) {
287
- useO(Model);
288
- const { useVMap, useOMap, fnMap, computedMap } = getActivePhecda();
289
- if (useVMap.has(Model))
290
- return useVMap.get(Model);
291
- computedMap.set(Model, {});
292
- const instance = useOMap.get(Model);
284
+ const { useVMap, fnMap, computedMap } = getActivePhecda();
285
+ const instance = useO(Model);
286
+ if (useVMap.has(instance))
287
+ return useVMap.get(instance);
288
+ computedMap.set(instance, {});
293
289
  const proxy = new Proxy(instance, {
294
290
  get(target, key) {
295
291
  if (typeof target[key] === "function") {
@@ -302,7 +298,7 @@ function useV(Model) {
302
298
  fnMap.set(target[key], wrapper);
303
299
  return wrapper;
304
300
  }
305
- const cache = computedMap.get(Model);
301
+ const cache = computedMap.get(instance);
306
302
  if (key in cache)
307
303
  return cache[key]();
308
304
  cache[key] = createSharedReactive(() => {
@@ -314,7 +310,7 @@ function useV(Model) {
314
310
  return false;
315
311
  }
316
312
  });
317
- useVMap.set(Model, proxy);
313
+ useVMap.set(instance, proxy);
318
314
  return proxy;
319
315
  }
320
316
  __name(useV, "useV");
@@ -326,11 +322,15 @@ function useEvent(eventName, cb) {
326
322
  return () => emitter.off(eventName, cb);
327
323
  }
328
324
  __name(useEvent, "useEvent");
329
- function initialize(Model) {
325
+ function initialize(Model, deleteOtherProperty = true) {
330
326
  const instance = useO(Model);
331
- if (instance) {
332
- Object.assign(instance, new Model());
333
- return instance;
327
+ const newInstance = new Model();
328
+ Object.assign(instance, newInstance);
329
+ if (deleteOtherProperty) {
330
+ for (const key in instance) {
331
+ if (!(key in newInstance))
332
+ delete instance[key];
333
+ }
334
334
  }
335
335
  }
336
336
  __name(initialize, "initialize");
package/dist/index.mjs CHANGED
@@ -199,18 +199,15 @@ function useRaw(Model) {
199
199
  }
200
200
  __name(useRaw, "useRaw");
201
201
  function usePatch(Model, Data) {
202
- useO(Model);
203
- const { useOMap } = getActivePhecda();
204
- const target = useOMap.get(Model);
205
- mergeReactiveObjects(target, Data);
202
+ const instance = useO(Model);
203
+ mergeReactiveObjects(instance, Data);
206
204
  }
207
205
  __name(usePatch, "usePatch");
208
206
  function useR(Model) {
209
- useO(Model);
210
- const { useRMap, useOMap, fnMap } = getActivePhecda();
211
- if (useRMap.has(Model))
212
- return useRMap.get(Model);
213
- const instance = useOMap.get(Model);
207
+ const { useRMap, fnMap } = getActivePhecda();
208
+ const instance = useO(Model);
209
+ if (useRMap.has(instance))
210
+ return useRMap.get(instance);
214
211
  const proxy = new Proxy(instance, {
215
212
  get(target, key) {
216
213
  if (typeof target[key] === "function") {
@@ -230,17 +227,16 @@ function useR(Model) {
230
227
  return true;
231
228
  }
232
229
  });
233
- useRMap.set(Model, proxy);
230
+ useRMap.set(instance, proxy);
234
231
  return proxy;
235
232
  }
236
233
  __name(useR, "useR");
237
234
  function useV(Model) {
238
- useO(Model);
239
- const { useVMap, useOMap, fnMap, computedMap } = getActivePhecda();
240
- if (useVMap.has(Model))
241
- return useVMap.get(Model);
242
- computedMap.set(Model, {});
243
- const instance = useOMap.get(Model);
235
+ const { useVMap, fnMap, computedMap } = getActivePhecda();
236
+ const instance = useO(Model);
237
+ if (useVMap.has(instance))
238
+ return useVMap.get(instance);
239
+ computedMap.set(instance, {});
244
240
  const proxy = new Proxy(instance, {
245
241
  get(target, key) {
246
242
  if (typeof target[key] === "function") {
@@ -253,7 +249,7 @@ function useV(Model) {
253
249
  fnMap.set(target[key], wrapper);
254
250
  return wrapper;
255
251
  }
256
- const cache = computedMap.get(Model);
252
+ const cache = computedMap.get(instance);
257
253
  if (key in cache)
258
254
  return cache[key]();
259
255
  cache[key] = createSharedReactive(() => {
@@ -265,7 +261,7 @@ function useV(Model) {
265
261
  return false;
266
262
  }
267
263
  });
268
- useVMap.set(Model, proxy);
264
+ useVMap.set(instance, proxy);
269
265
  return proxy;
270
266
  }
271
267
  __name(useV, "useV");
@@ -277,11 +273,15 @@ function useEvent(eventName, cb) {
277
273
  return () => emitter.off(eventName, cb);
278
274
  }
279
275
  __name(useEvent, "useEvent");
280
- function initialize(Model) {
276
+ function initialize(Model, deleteOtherProperty = true) {
281
277
  const instance = useO(Model);
282
- if (instance) {
283
- Object.assign(instance, new Model());
284
- return instance;
278
+ const newInstance = new Model();
279
+ Object.assign(instance, newInstance);
280
+ if (deleteOtherProperty) {
281
+ for (const key in instance) {
282
+ if (!(key in newInstance))
283
+ delete instance[key];
284
+ }
285
285
  }
286
286
  }
287
287
  __name(initialize, "initialize");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-vue",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "provide store/form/table with phecda function to vue",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",