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

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,28 @@ 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");
234
246
  function useO(module2) {
235
- const { state, _o: oMap } = (0, import_phecda_web3.getActiveInstance)();
247
+ const { state, origin } = (0, import_phecda_web3.getActiveInstance)();
248
+ const proxyFn = module2.prototype.__SHALLOW__ ? import_vue4.shallowReactive : import_vue4.reactive;
236
249
  if (module2.prototype.__ISOLATE__) {
237
- const instance = (0, import_vue4.reactive)(new module2());
250
+ const instance = proxyFn(new module2());
238
251
  instance._promise = (0, import_phecda_web3.invokeHandler)("init", instance);
239
252
  return instance;
240
253
  }
241
254
  const tag = (0, import_phecda_web3.getTag)(module2);
242
255
  if (!(tag in state)) {
243
- const instance = (0, import_vue4.reactive)(new module2());
256
+ const instance = proxyFn(new module2());
244
257
  instance._promise = (0, import_phecda_web3.invokeHandler)("init", instance);
245
258
  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}"`);
259
+ origin.set(instance, module2);
250
260
  }
251
261
  return state[tag];
252
262
  }
@@ -261,54 +271,27 @@ function usePatch(module2, Data) {
261
271
  }
262
272
  __name(usePatch, "usePatch");
263
273
  function useR(module2) {
264
- const { _r: rmap, _f: fmap } = (0, import_phecda_web3.getActiveInstance)();
265
- const instance = useO(module2);
266
- if (rmap.has(instance))
267
- return rmap.get(instance);
268
- const proxy = new Proxy(instance, {
269
- get(target, key) {
270
- if (typeof target[key] === "function") {
271
- if (fmap.has(target[key]))
272
- return fmap.get(target[key]);
273
- const errorHandler = (0, import_phecda_web3.getHandler)(target, key).find((item) => item.error)?.error;
274
- if (!errorHandler)
275
- return target[key].bind(target);
276
- const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
277
- fmap.set(target[key], wrapper);
278
- return wrapper;
279
- }
280
- return target[key];
281
- },
282
- set(target, key, v) {
283
- target[key] = v;
284
- return true;
285
- }
286
- });
287
- rmap.set(instance, proxy);
288
- return proxy;
274
+ return useO(module2);
289
275
  }
290
276
  __name(useR, "useR");
291
277
  function useV(module2) {
292
- const { _v: vmap, _f: fmap, _c: cmap } = (0, import_phecda_web3.getActiveInstance)();
278
+ const { cache: cacheMap } = (0, import_phecda_web3.getActiveInstance)();
293
279
  const instance = useO(module2);
294
- if (vmap.has(instance))
295
- return vmap.get(instance);
296
- cmap.set(instance, {});
280
+ const cache = cacheMap.get(instance) || {};
281
+ if (cache[REF_SYMBOL])
282
+ return cache[REF_SYMBOL];
297
283
  const proxy = new Proxy(instance, {
298
284
  get(target, key) {
299
285
  if (typeof target[key] === "function") {
300
- if (fmap.has(target[key]))
301
- return fmap.get(target[key]);
302
- const errorHandler = (0, import_phecda_web3.getHandler)(target, key).find((item) => item.error)?.error;
303
- if (!errorHandler)
304
- return target[key].bind(target);
305
- const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
306
- fmap.set(target[key], wrapper);
307
- return wrapper;
286
+ if (!cache[key])
287
+ cache[key] = target[key].bind(this);
288
+ return cache[key];
308
289
  }
309
- const cache = cmap.get(instance);
310
- if (key in cache)
311
- return cache[key]();
290
+ if (target[key]?.__v_skip)
291
+ return target[key];
292
+ const cacheRef = cache[key];
293
+ if (cacheRef && cacheRef.r)
294
+ return cacheRef();
312
295
  cache[key] = createSharedReactive(() => {
313
296
  return (0, import_vue4.toRef)(target, key);
314
297
  });
@@ -318,7 +301,9 @@ function useV(module2) {
318
301
  return false;
319
302
  }
320
303
  });
321
- vmap.set(instance, proxy);
304
+ cache[REF_SYMBOL] = proxy;
305
+ if (!cacheMap.has(instance))
306
+ cacheMap.set(instance, cache);
322
307
  return proxy;
323
308
  }
324
309
  __name(useV, "useV");
@@ -345,13 +330,26 @@ function initialize(module2, deleteOtherProperty = true) {
345
330
  }
346
331
  }
347
332
  __name(initialize, "initialize");
333
+
334
+ // src/decorator.ts
335
+ var import_phecda_web4 = require("phecda-web");
336
+ function Shallow(module2) {
337
+ (0, import_phecda_web4.init)(module2.prototype);
338
+ module2.prototype.__SHALLOW__ = true;
339
+ }
340
+ __name(Shallow, "Shallow");
348
341
  // Annotate the CommonJS export names for ESM import in node:
349
342
  0 && (module.exports = {
350
343
  PV,
351
344
  RE,
345
+ Shallow,
352
346
  createFilter,
353
347
  createPhecda,
348
+ createSharedReactive,
354
349
  initialize,
350
+ isObject,
351
+ markRaw,
352
+ mergeReactiveObjects,
355
353
  phecdaSymbol,
356
354
  useEvent,
357
355
  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";
152
- import { emitter as emitter2, getActiveInstance as getActiveInstance2, getHandler, getTag, invokeHandler as invokeHandler2, wrapError } from "phecda-web";
151
+ import { onBeforeUnmount, reactive, shallowReactive, toRaw, toRef } from "vue";
152
+ import { emitter as emitter2, getActiveInstance as getActiveInstance2, getTag, invokeHandler as invokeHandler2 } 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,28 @@ 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");
198
205
  function useO(module) {
199
- const { state, _o: oMap } = getActiveInstance2();
206
+ const { state, origin } = getActiveInstance2();
207
+ const proxyFn = module.prototype.__SHALLOW__ ? shallowReactive : reactive;
200
208
  if (module.prototype.__ISOLATE__) {
201
- const instance = reactive(new module());
209
+ const instance = proxyFn(new module());
202
210
  instance._promise = invokeHandler2("init", instance);
203
211
  return instance;
204
212
  }
205
213
  const tag = getTag(module);
206
214
  if (!(tag in state)) {
207
- const instance = reactive(new module());
215
+ const instance = proxyFn(new module());
208
216
  instance._promise = invokeHandler2("init", instance);
209
217
  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}"`);
218
+ origin.set(instance, module);
214
219
  }
215
220
  return state[tag];
216
221
  }
@@ -225,54 +230,27 @@ function usePatch(module, Data) {
225
230
  }
226
231
  __name(usePatch, "usePatch");
227
232
  function useR(module) {
228
- const { _r: rmap, _f: fmap } = getActiveInstance2();
229
- const instance = useO(module);
230
- if (rmap.has(instance))
231
- return rmap.get(instance);
232
- const proxy = new Proxy(instance, {
233
- get(target, key) {
234
- if (typeof target[key] === "function") {
235
- if (fmap.has(target[key]))
236
- return fmap.get(target[key]);
237
- const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
238
- if (!errorHandler)
239
- return target[key].bind(target);
240
- const wrapper = wrapError(target, key, errorHandler);
241
- fmap.set(target[key], wrapper);
242
- return wrapper;
243
- }
244
- return target[key];
245
- },
246
- set(target, key, v) {
247
- target[key] = v;
248
- return true;
249
- }
250
- });
251
- rmap.set(instance, proxy);
252
- return proxy;
233
+ return useO(module);
253
234
  }
254
235
  __name(useR, "useR");
255
236
  function useV(module) {
256
- const { _v: vmap, _f: fmap, _c: cmap } = getActiveInstance2();
237
+ const { cache: cacheMap } = getActiveInstance2();
257
238
  const instance = useO(module);
258
- if (vmap.has(instance))
259
- return vmap.get(instance);
260
- cmap.set(instance, {});
239
+ const cache = cacheMap.get(instance) || {};
240
+ if (cache[REF_SYMBOL])
241
+ return cache[REF_SYMBOL];
261
242
  const proxy = new Proxy(instance, {
262
243
  get(target, key) {
263
244
  if (typeof target[key] === "function") {
264
- if (fmap.has(target[key]))
265
- return fmap.get(target[key]);
266
- const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
267
- if (!errorHandler)
268
- return target[key].bind(target);
269
- const wrapper = wrapError(target, key, errorHandler);
270
- fmap.set(target[key], wrapper);
271
- return wrapper;
245
+ if (!cache[key])
246
+ cache[key] = target[key].bind(this);
247
+ return cache[key];
272
248
  }
273
- const cache = cmap.get(instance);
274
- if (key in cache)
275
- return cache[key]();
249
+ if (target[key]?.__v_skip)
250
+ return target[key];
251
+ const cacheRef = cache[key];
252
+ if (cacheRef && cacheRef.r)
253
+ return cacheRef();
276
254
  cache[key] = createSharedReactive(() => {
277
255
  return toRef(target, key);
278
256
  });
@@ -282,7 +260,9 @@ function useV(module) {
282
260
  return false;
283
261
  }
284
262
  });
285
- vmap.set(instance, proxy);
263
+ cache[REF_SYMBOL] = proxy;
264
+ if (!cacheMap.has(instance))
265
+ cacheMap.set(instance, cache);
286
266
  return proxy;
287
267
  }
288
268
  __name(useV, "useV");
@@ -309,12 +289,25 @@ function initialize(module, deleteOtherProperty = true) {
309
289
  }
310
290
  }
311
291
  __name(initialize, "initialize");
292
+
293
+ // src/decorator.ts
294
+ import { init } from "phecda-web";
295
+ function Shallow(module) {
296
+ init(module.prototype);
297
+ module.prototype.__SHALLOW__ = true;
298
+ }
299
+ __name(Shallow, "Shallow");
312
300
  export {
313
301
  PV,
314
302
  RE,
303
+ Shallow,
315
304
  createFilter,
316
305
  createPhecda,
306
+ createSharedReactive,
317
307
  initialize,
308
+ isObject,
309
+ markRaw2 as markRaw,
310
+ mergeReactiveObjects,
318
311
  phecdaSymbol,
319
312
  useEvent,
320
313
  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.14",
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.8"
17
17
  },
18
18
  "devDependencies": {
19
19
  "tsup": "^6.5.0"