phecda-vue 3.0.0-alpha.12 → 3.0.0-alpha.13

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
@@ -1,10 +1,14 @@
1
- import * as _vue_reactivity from '@vue/reactivity';
1
+ import * as vue from 'vue';
2
2
  import { Ref, App, UnwrapNestedRefs } from 'vue';
3
3
  import { Events, Construct } from 'phecda-web';
4
4
  export * from 'phecda-web';
5
5
 
6
+ declare const RawSymbol: unique symbol;
7
+ type Raw<T> = T & {
8
+ [RawSymbol]: true;
9
+ };
6
10
  type ReplaceInstanceValues<I> = {
7
- [P in keyof I]: I[P] extends (...args: any[]) => any ? I[P] : Ref<I[P]>;
11
+ [P in keyof I]: I[P] extends (...args: any[]) => any ? I[P] : I[P] extends Raw<infer O> ? O : Ref<I[P]>;
8
12
  };
9
13
  type SchemaToObj<S> = {
10
14
  [P in keyof S]: S[P] extends object ? SchemaToObj<S[P]> : (S[P] extends string ? any : S[P]);
@@ -18,7 +22,7 @@ declare function createFilter<Data extends Record<string, any>>(initState?: Obje
18
22
  errorHandler?: (error?: Error, errorPath?: string) => any;
19
23
  }): {
20
24
  filter: <Schema>(obj: Schema) => SchemaToObj<Schema>;
21
- data: [Data] extends [_vue_reactivity.Ref<any>] ? Data : _vue_reactivity.Ref<_vue_reactivity.UnwrapRef<Data>>;
25
+ data: [Data] extends [vue.Ref<any>] ? Data : vue.Ref<vue.UnwrapRef<Data>>;
22
26
  init: (params?: Data) => void;
23
27
  setState: <Key extends string>(key: Key, value: Data[Key]) => void;
24
28
  storeState: (key: string, params?: Data) => void;
@@ -40,7 +44,7 @@ declare class PV {
40
44
  }
41
45
 
42
46
  declare const phecdaSymbol: unique symbol;
43
- declare function createPhecda(): _vue_reactivity.Raw<{
47
+ declare function createPhecda(): vue.Raw<{
44
48
  install(app: App): void;
45
49
  load(state: any): any;
46
50
  unmount(): Promise<void>;
@@ -49,6 +53,10 @@ declare function createPhecda(): _vue_reactivity.Raw<{
49
53
  type DeepPartial<T> = {
50
54
  [K in keyof T]?: DeepPartial<T[K]>;
51
55
  };
56
+ declare function markRaw<T extends object>(value: T): Raw<T>;
57
+ declare function isObject(o: any): boolean;
58
+ declare function mergeReactiveObjects<T extends Record<any, unknown> | Map<unknown, unknown> | Set<unknown>>(target: T, patchToApply: DeepPartial<T>): T;
59
+ declare function createSharedReactive<F extends (...args: any) => any>(composable: F): () => ReturnType<F>;
52
60
 
53
61
  declare function useO<T extends Construct>(module: T): UnwrapNestedRefs<InstanceType<T>>;
54
62
  declare function useRaw<T extends Construct>(module: T): InstanceType<T>;
@@ -61,4 +69,6 @@ declare function useEvent<Key extends keyof Events>(eventName: Key, cb: (event:
61
69
  };
62
70
  declare function initialize<M extends Construct>(module: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
63
71
 
64
- export { PV, RE, createFilter, createPhecda, initialize, phecdaSymbol, useEvent, useO, usePatch, useR, useRaw, useV };
72
+ declare function Shallow(module: any): void;
73
+
74
+ export { DeepPartial, PV, RE, Raw, RawSymbol, ReplaceInstanceValues, SchemaToObj, Shallow, createFilter, createPhecda, createSharedReactive, initialize, isObject, markRaw, mergeReactiveObjects, phecdaSymbol, useEvent, useO, usePatch, useR, useRaw, useV };
package/dist/index.js CHANGED
@@ -24,9 +24,14 @@ var src_exports = {};
24
24
  __export(src_exports, {
25
25
  PV: () => PV,
26
26
  RE: () => RE,
27
+ Shallow: () => Shallow,
27
28
  createFilter: () => createFilter,
28
29
  createPhecda: () => createPhecda,
30
+ createSharedReactive: () => createSharedReactive,
29
31
  initialize: () => initialize,
32
+ isObject: () => isObject,
33
+ markRaw: () => markRaw2,
34
+ mergeReactiveObjects: () => mergeReactiveObjects,
30
35
  phecdaSymbol: () => phecdaSymbol,
31
36
  useEvent: () => useEvent,
32
37
  useO: () => useO,
@@ -90,7 +95,7 @@ function createFilter(initState = {}, option = {}) {
90
95
  __name(setState, "setState");
91
96
  function storeState(key, params) {
92
97
  store[key] = data.value;
93
- init(params);
98
+ init2(params);
94
99
  }
95
100
  __name(storeState, "storeState");
96
101
  function applyStore(key) {
@@ -99,10 +104,10 @@ function createFilter(initState = {}, option = {}) {
99
104
  data.value = store[key];
100
105
  }
101
106
  __name(applyStore, "applyStore");
102
- function init(params) {
107
+ function init2(params) {
103
108
  data.value = params || initState || {};
104
109
  }
105
- __name(init, "init");
110
+ __name(init2, "init");
106
111
  function delState(key) {
107
112
  delete data.value[key];
108
113
  }
@@ -120,7 +125,7 @@ function createFilter(initState = {}, option = {}) {
120
125
  return {
121
126
  filter,
122
127
  data,
123
- init,
128
+ init: init2,
124
129
  setState,
125
130
  storeState,
126
131
  store,
@@ -189,6 +194,10 @@ var import_phecda_web3 = require("phecda-web");
189
194
 
190
195
  // src/utils.ts
191
196
  var import_vue3 = require("vue");
197
+ function markRaw2(value) {
198
+ return (0, import_vue3.markRaw)(value);
199
+ }
200
+ __name(markRaw2, "markRaw");
192
201
  function isObject(o) {
193
202
  return Object.prototype.toString.call(o) === "[object Object]";
194
203
  }
@@ -218,7 +227,7 @@ function createSharedReactive(composable) {
218
227
  state = scope = null;
219
228
  }
220
229
  }, "dispose");
221
- return () => {
230
+ const cb = /* @__PURE__ */ __name(() => {
222
231
  subscribers++;
223
232
  if (!state) {
224
233
  scope = (0, import_vue3.effectScope)(true);
@@ -226,27 +235,29 @@ function createSharedReactive(composable) {
226
235
  }
227
236
  (0, import_vue3.onScopeDispose)(dispose);
228
237
  return state;
229
- };
238
+ }, "cb");
239
+ cb.r = true;
240
+ return cb;
230
241
  }
231
242
  __name(createSharedReactive, "createSharedReactive");
232
243
 
233
244
  // src/composable.ts
245
+ var REF_SYMBOL = Symbol("ref");
246
+ var REACTIVE_SYMBOL = Symbol("reactive");
234
247
  function useO(module2) {
235
- const { state, _o: oMap } = (0, import_phecda_web3.getActiveInstance)();
248
+ const { state, origin } = (0, import_phecda_web3.getActiveInstance)();
249
+ const proxyFn = module2.prototype.__SHALLOW__ ? import_vue4.shallowReactive : import_vue4.reactive;
236
250
  if (module2.prototype.__ISOLATE__) {
237
- const instance = (0, import_vue4.reactive)(new module2());
251
+ const instance = proxyFn(new module2());
238
252
  instance._promise = (0, import_phecda_web3.invokeHandler)("init", instance);
239
253
  return instance;
240
254
  }
241
255
  const tag = (0, import_phecda_web3.getTag)(module2);
242
256
  if (!(tag in state)) {
243
- const instance = (0, import_vue4.reactive)(new module2());
257
+ const instance = proxyFn(new module2());
244
258
  instance._promise = (0, import_phecda_web3.invokeHandler)("init", instance);
245
259
  state[tag] = instance;
246
- oMap.set(instance, module2);
247
- } else {
248
- if (oMap.get(state[tag]) !== module2)
249
- console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${module2.name}"`);
260
+ origin.set(instance, module2);
250
261
  }
251
262
  return state[tag];
252
263
  }
@@ -261,20 +272,21 @@ function usePatch(module2, Data) {
261
272
  }
262
273
  __name(usePatch, "usePatch");
263
274
  function useR(module2) {
264
- const { _r: rmap, _f: fmap } = (0, import_phecda_web3.getActiveInstance)();
275
+ const { cache: cacheMap } = (0, import_phecda_web3.getActiveInstance)();
265
276
  const instance = useO(module2);
266
- if (rmap.has(instance))
267
- return rmap.get(instance);
277
+ const cache = cacheMap.get(instance) || {};
278
+ if (cache[REACTIVE_SYMBOL])
279
+ return cache[REACTIVE_SYMBOL];
268
280
  const proxy = new Proxy(instance, {
269
281
  get(target, key) {
270
282
  if (typeof target[key] === "function") {
271
- if (fmap.has(target[key]))
272
- return fmap.get(target[key]);
283
+ if (cache[key])
284
+ return cache[key];
273
285
  const errorHandler = (0, import_phecda_web3.getHandler)(target, key).find((item) => item.error)?.error;
274
286
  if (!errorHandler)
275
287
  return target[key].bind(target);
276
288
  const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
277
- fmap.set(target[key], wrapper);
289
+ cache[key] = wrapper;
278
290
  return wrapper;
279
291
  }
280
292
  return target[key];
@@ -284,31 +296,35 @@ function useR(module2) {
284
296
  return true;
285
297
  }
286
298
  });
287
- rmap.set(instance, proxy);
299
+ cache[REACTIVE_SYMBOL] = proxy;
300
+ if (!cacheMap.has(instance))
301
+ cacheMap.set(instance, cache);
288
302
  return proxy;
289
303
  }
290
304
  __name(useR, "useR");
291
305
  function useV(module2) {
292
- const { _v: vmap, _f: fmap, _c: cmap } = (0, import_phecda_web3.getActiveInstance)();
306
+ const { cache: cacheMap } = (0, import_phecda_web3.getActiveInstance)();
293
307
  const instance = useO(module2);
294
- if (vmap.has(instance))
295
- return vmap.get(instance);
296
- cmap.set(instance, {});
308
+ const cache = cacheMap.get(instance) || {};
309
+ if (cache[REF_SYMBOL])
310
+ return cache[REF_SYMBOL];
297
311
  const proxy = new Proxy(instance, {
298
312
  get(target, key) {
299
313
  if (typeof target[key] === "function") {
300
- if (fmap.has(target[key]))
301
- return fmap.get(target[key]);
314
+ if (cache[key])
315
+ return cache[key];
302
316
  const errorHandler = (0, import_phecda_web3.getHandler)(target, key).find((item) => item.error)?.error;
303
317
  if (!errorHandler)
304
318
  return target[key].bind(target);
305
319
  const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
306
- fmap.set(target[key], wrapper);
320
+ cache[key] = wrapper;
307
321
  return wrapper;
308
322
  }
309
- const cache = cmap.get(instance);
310
- if (key in cache)
311
- return cache[key]();
323
+ if (target[key]?.__v_skip)
324
+ return target[key];
325
+ const cacheRef = cache[key];
326
+ if (cacheRef && cacheRef.r)
327
+ return cacheRef();
312
328
  cache[key] = createSharedReactive(() => {
313
329
  return (0, import_vue4.toRef)(target, key);
314
330
  });
@@ -318,7 +334,9 @@ function useV(module2) {
318
334
  return false;
319
335
  }
320
336
  });
321
- vmap.set(instance, proxy);
337
+ cache[REF_SYMBOL] = proxy;
338
+ if (!cacheMap.has(instance))
339
+ cacheMap.set(instance, cache);
322
340
  return proxy;
323
341
  }
324
342
  __name(useV, "useV");
@@ -345,13 +363,26 @@ function initialize(module2, deleteOtherProperty = true) {
345
363
  }
346
364
  }
347
365
  __name(initialize, "initialize");
366
+
367
+ // src/decorator.ts
368
+ var import_phecda_web4 = require("phecda-web");
369
+ function Shallow(module2) {
370
+ (0, import_phecda_web4.init)(module2.prototype);
371
+ module2.prototype.__SHALLOW__ = true;
372
+ }
373
+ __name(Shallow, "Shallow");
348
374
  // Annotate the CommonJS export names for ESM import in node:
349
375
  0 && (module.exports = {
350
376
  PV,
351
377
  RE,
378
+ Shallow,
352
379
  createFilter,
353
380
  createPhecda,
381
+ createSharedReactive,
354
382
  initialize,
383
+ isObject,
384
+ markRaw,
385
+ mergeReactiveObjects,
355
386
  phecdaSymbol,
356
387
  useEvent,
357
388
  useO,
package/dist/index.mjs CHANGED
@@ -54,7 +54,7 @@ function createFilter(initState = {}, option = {}) {
54
54
  __name(setState, "setState");
55
55
  function storeState(key, params) {
56
56
  store[key] = data.value;
57
- init(params);
57
+ init2(params);
58
58
  }
59
59
  __name(storeState, "storeState");
60
60
  function applyStore(key) {
@@ -63,10 +63,10 @@ function createFilter(initState = {}, option = {}) {
63
63
  data.value = store[key];
64
64
  }
65
65
  __name(applyStore, "applyStore");
66
- function init(params) {
66
+ function init2(params) {
67
67
  data.value = params || initState || {};
68
68
  }
69
- __name(init, "init");
69
+ __name(init2, "init");
70
70
  function delState(key) {
71
71
  delete data.value[key];
72
72
  }
@@ -84,7 +84,7 @@ function createFilter(initState = {}, option = {}) {
84
84
  return {
85
85
  filter,
86
86
  data,
87
- init,
87
+ init: init2,
88
88
  setState,
89
89
  storeState,
90
90
  store,
@@ -148,11 +148,15 @@ function createPhecda() {
148
148
  __name(createPhecda, "createPhecda");
149
149
 
150
150
  // src/composable.ts
151
- import { onBeforeUnmount, reactive, toRaw, toRef } from "vue";
151
+ import { onBeforeUnmount, reactive, shallowReactive, toRaw, toRef } from "vue";
152
152
  import { emitter as emitter2, getActiveInstance as getActiveInstance2, getHandler, getTag, invokeHandler as invokeHandler2, wrapError } from "phecda-web";
153
153
 
154
154
  // src/utils.ts
155
- import { effectScope as effectScope2, isReactive, isRef, onScopeDispose } from "vue";
155
+ import { effectScope as effectScope2, isReactive, isRef, onScopeDispose, markRaw as raw } from "vue";
156
+ function markRaw2(value) {
157
+ return raw(value);
158
+ }
159
+ __name(markRaw2, "markRaw");
156
160
  function isObject(o) {
157
161
  return Object.prototype.toString.call(o) === "[object Object]";
158
162
  }
@@ -182,7 +186,7 @@ function createSharedReactive(composable) {
182
186
  state = scope = null;
183
187
  }
184
188
  }, "dispose");
185
- return () => {
189
+ const cb = /* @__PURE__ */ __name(() => {
186
190
  subscribers++;
187
191
  if (!state) {
188
192
  scope = effectScope2(true);
@@ -190,27 +194,29 @@ function createSharedReactive(composable) {
190
194
  }
191
195
  onScopeDispose(dispose);
192
196
  return state;
193
- };
197
+ }, "cb");
198
+ cb.r = true;
199
+ return cb;
194
200
  }
195
201
  __name(createSharedReactive, "createSharedReactive");
196
202
 
197
203
  // src/composable.ts
204
+ var REF_SYMBOL = Symbol("ref");
205
+ var REACTIVE_SYMBOL = Symbol("reactive");
198
206
  function useO(module) {
199
- const { state, _o: oMap } = getActiveInstance2();
207
+ const { state, origin } = getActiveInstance2();
208
+ const proxyFn = module.prototype.__SHALLOW__ ? shallowReactive : reactive;
200
209
  if (module.prototype.__ISOLATE__) {
201
- const instance = reactive(new module());
210
+ const instance = proxyFn(new module());
202
211
  instance._promise = invokeHandler2("init", instance);
203
212
  return instance;
204
213
  }
205
214
  const tag = getTag(module);
206
215
  if (!(tag in state)) {
207
- const instance = reactive(new module());
216
+ const instance = proxyFn(new module());
208
217
  instance._promise = invokeHandler2("init", instance);
209
218
  state[tag] = instance;
210
- oMap.set(instance, module);
211
- } else {
212
- if (oMap.get(state[tag]) !== module)
213
- console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${module.name}"`);
219
+ origin.set(instance, module);
214
220
  }
215
221
  return state[tag];
216
222
  }
@@ -225,20 +231,21 @@ function usePatch(module, Data) {
225
231
  }
226
232
  __name(usePatch, "usePatch");
227
233
  function useR(module) {
228
- const { _r: rmap, _f: fmap } = getActiveInstance2();
234
+ const { cache: cacheMap } = getActiveInstance2();
229
235
  const instance = useO(module);
230
- if (rmap.has(instance))
231
- return rmap.get(instance);
236
+ const cache = cacheMap.get(instance) || {};
237
+ if (cache[REACTIVE_SYMBOL])
238
+ return cache[REACTIVE_SYMBOL];
232
239
  const proxy = new Proxy(instance, {
233
240
  get(target, key) {
234
241
  if (typeof target[key] === "function") {
235
- if (fmap.has(target[key]))
236
- return fmap.get(target[key]);
242
+ if (cache[key])
243
+ return cache[key];
237
244
  const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
238
245
  if (!errorHandler)
239
246
  return target[key].bind(target);
240
247
  const wrapper = wrapError(target, key, errorHandler);
241
- fmap.set(target[key], wrapper);
248
+ cache[key] = wrapper;
242
249
  return wrapper;
243
250
  }
244
251
  return target[key];
@@ -248,31 +255,35 @@ function useR(module) {
248
255
  return true;
249
256
  }
250
257
  });
251
- rmap.set(instance, proxy);
258
+ cache[REACTIVE_SYMBOL] = proxy;
259
+ if (!cacheMap.has(instance))
260
+ cacheMap.set(instance, cache);
252
261
  return proxy;
253
262
  }
254
263
  __name(useR, "useR");
255
264
  function useV(module) {
256
- const { _v: vmap, _f: fmap, _c: cmap } = getActiveInstance2();
265
+ const { cache: cacheMap } = getActiveInstance2();
257
266
  const instance = useO(module);
258
- if (vmap.has(instance))
259
- return vmap.get(instance);
260
- cmap.set(instance, {});
267
+ const cache = cacheMap.get(instance) || {};
268
+ if (cache[REF_SYMBOL])
269
+ return cache[REF_SYMBOL];
261
270
  const proxy = new Proxy(instance, {
262
271
  get(target, key) {
263
272
  if (typeof target[key] === "function") {
264
- if (fmap.has(target[key]))
265
- return fmap.get(target[key]);
273
+ if (cache[key])
274
+ return cache[key];
266
275
  const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
267
276
  if (!errorHandler)
268
277
  return target[key].bind(target);
269
278
  const wrapper = wrapError(target, key, errorHandler);
270
- fmap.set(target[key], wrapper);
279
+ cache[key] = wrapper;
271
280
  return wrapper;
272
281
  }
273
- const cache = cmap.get(instance);
274
- if (key in cache)
275
- return cache[key]();
282
+ if (target[key]?.__v_skip)
283
+ return target[key];
284
+ const cacheRef = cache[key];
285
+ if (cacheRef && cacheRef.r)
286
+ return cacheRef();
276
287
  cache[key] = createSharedReactive(() => {
277
288
  return toRef(target, key);
278
289
  });
@@ -282,7 +293,9 @@ function useV(module) {
282
293
  return false;
283
294
  }
284
295
  });
285
- vmap.set(instance, proxy);
296
+ cache[REF_SYMBOL] = proxy;
297
+ if (!cacheMap.has(instance))
298
+ cacheMap.set(instance, cache);
286
299
  return proxy;
287
300
  }
288
301
  __name(useV, "useV");
@@ -309,12 +322,25 @@ function initialize(module, deleteOtherProperty = true) {
309
322
  }
310
323
  }
311
324
  __name(initialize, "initialize");
325
+
326
+ // src/decorator.ts
327
+ import { init } from "phecda-web";
328
+ function Shallow(module) {
329
+ init(module.prototype);
330
+ module.prototype.__SHALLOW__ = true;
331
+ }
332
+ __name(Shallow, "Shallow");
312
333
  export {
313
334
  PV,
314
335
  RE,
336
+ Shallow,
315
337
  createFilter,
316
338
  createPhecda,
339
+ createSharedReactive,
317
340
  initialize,
341
+ isObject,
342
+ markRaw2 as markRaw,
343
+ mergeReactiveObjects,
318
344
  phecdaSymbol,
319
345
  useEvent,
320
346
  useO,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-vue",
3
- "version": "3.0.0-alpha.12",
3
+ "version": "3.0.0-alpha.13",
4
4
  "description": "provide phecda function to vue",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -13,7 +13,7 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "vue": "^3.2.45",
16
- "phecda-web": "1.0.1-alpha.6"
16
+ "phecda-web": "1.0.1-alpha.7"
17
17
  },
18
18
  "devDependencies": {
19
19
  "tsup": "^6.5.0"