phecda-vue 5.0.0 → 5.1.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/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +65 -0
- package/dist/index.mjs +62 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -36,4 +36,8 @@ declare function WatchEffect(option?: WatchOptions): (proto: any, key: string) =
|
|
|
36
36
|
declare function markRaw<T extends object>(value: T): Raw<T>;
|
|
37
37
|
declare function createSharedReactive<F extends (...args: any) => any>(composable: F): () => ReturnType<F>;
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
declare function hasI(model: Construct): boolean;
|
|
40
|
+
declare function useIR<T extends Construct>(model: T, forceProvide?: boolean): UnwrapNestedRefs<InstanceType<T>>;
|
|
41
|
+
declare function useIV<T extends Construct>(model: T, forceProvide?: boolean): ReplaceInstanceValues<InstanceType<T>>;
|
|
42
|
+
|
|
43
|
+
export { type Raw, RawSymbol, type ReplaceInstanceValues, Shallow, VuePhecda, WatchEffect, createPhecda, createSharedReactive, getPhecda, getR, getRaw, getV, hasI, markRaw, phecdaSymbol, useEvent, useIR, useIV, usePhecda, useR, useRaw, useV };
|
package/dist/index.d.ts
CHANGED
|
@@ -36,4 +36,8 @@ declare function WatchEffect(option?: WatchOptions): (proto: any, key: string) =
|
|
|
36
36
|
declare function markRaw<T extends object>(value: T): Raw<T>;
|
|
37
37
|
declare function createSharedReactive<F extends (...args: any) => any>(composable: F): () => ReturnType<F>;
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
declare function hasI(model: Construct): boolean;
|
|
40
|
+
declare function useIR<T extends Construct>(model: T, forceProvide?: boolean): UnwrapNestedRefs<InstanceType<T>>;
|
|
41
|
+
declare function useIV<T extends Construct>(model: T, forceProvide?: boolean): ReplaceInstanceValues<InstanceType<T>>;
|
|
42
|
+
|
|
43
|
+
export { type Raw, RawSymbol, type ReplaceInstanceValues, Shallow, VuePhecda, WatchEffect, createPhecda, createSharedReactive, getPhecda, getR, getRaw, getV, hasI, markRaw, phecdaSymbol, useEvent, useIR, useIV, usePhecda, useR, useRaw, useV };
|
package/dist/index.js
CHANGED
|
@@ -31,9 +31,12 @@ __export(src_exports, {
|
|
|
31
31
|
getR: () => getR,
|
|
32
32
|
getRaw: () => getRaw,
|
|
33
33
|
getV: () => getV,
|
|
34
|
+
hasI: () => hasI,
|
|
34
35
|
markRaw: () => markRaw,
|
|
35
36
|
phecdaSymbol: () => phecdaSymbol,
|
|
36
37
|
useEvent: () => useEvent,
|
|
38
|
+
useIR: () => useIR,
|
|
39
|
+
useIV: () => useIV,
|
|
37
40
|
usePhecda: () => usePhecda,
|
|
38
41
|
useR: () => useR,
|
|
39
42
|
useRaw: () => useRaw,
|
|
@@ -537,6 +540,65 @@ function WatchEffect(option) {
|
|
|
537
540
|
};
|
|
538
541
|
}
|
|
539
542
|
__name(WatchEffect, "WatchEffect");
|
|
543
|
+
|
|
544
|
+
// src/lib.ts
|
|
545
|
+
var import_phecda_web4 = require("phecda-web");
|
|
546
|
+
var import_vue5 = require("vue");
|
|
547
|
+
function hasI(model) {
|
|
548
|
+
const tag = (0, import_phecda_web4.getTag)(model);
|
|
549
|
+
const injectKey = `phecda-vue:lib ${tag.toString()}`;
|
|
550
|
+
return !!(0, import_vue5.inject)(injectKey);
|
|
551
|
+
}
|
|
552
|
+
__name(hasI, "hasI");
|
|
553
|
+
function useIR(model, forceProvide = false) {
|
|
554
|
+
const tag = (0, import_phecda_web4.getTag)(model);
|
|
555
|
+
const instance = (0, import_vue5.getCurrentInstance)();
|
|
556
|
+
if (!instance["phecda-vue"]) instance["phecda-vue"] = /* @__PURE__ */ new WeakMap();
|
|
557
|
+
const modelMap = instance["phecda-vue"];
|
|
558
|
+
const injectKey = `phecda-vue:lib ${tag.toString()}`;
|
|
559
|
+
let existModule = modelMap.get(model) || (0, import_vue5.inject)(injectKey);
|
|
560
|
+
if (!existModule || forceProvide) {
|
|
561
|
+
const data = {
|
|
562
|
+
// keep class name
|
|
563
|
+
[model.name]: class extends model {
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
const paramtypes = (0, import_phecda_web4.getParamtypes)(model) || [];
|
|
567
|
+
existModule = (0, import_phecda_web4.bindMethod)((0, import_vue5.reactive)(new data[model.name](...paramtypes.map((param) => useIR(param)))));
|
|
568
|
+
(0, import_phecda_web4.invokeInit)(existModule);
|
|
569
|
+
(0, import_vue5.provide)(injectKey, existModule);
|
|
570
|
+
modelMap.set(model, existModule);
|
|
571
|
+
(0, import_vue5.onBeforeUnmount)(() => (0, import_phecda_web4.invokeUnmount)(existModule));
|
|
572
|
+
return existModule;
|
|
573
|
+
} else {
|
|
574
|
+
return existModule;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
__name(useIR, "useIR");
|
|
578
|
+
var weakmap = /* @__PURE__ */ new WeakMap();
|
|
579
|
+
function useIV(model, forceProvide = false) {
|
|
580
|
+
const instance = useIR(model, forceProvide);
|
|
581
|
+
if (weakmap.has(instance)) return weakmap.get(instance);
|
|
582
|
+
const cache = {};
|
|
583
|
+
const proxy = new Proxy(instance, {
|
|
584
|
+
get(target, key) {
|
|
585
|
+
if (typeof target[key] === "function") return target[key];
|
|
586
|
+
if (target[key]?.__v_skip) return target[key];
|
|
587
|
+
const cacheRef = cache[key];
|
|
588
|
+
if (cacheRef && cacheRef.r) return cacheRef();
|
|
589
|
+
cache[key] = createSharedReactive(() => {
|
|
590
|
+
return (0, import_vue5.toRef)(target, key);
|
|
591
|
+
});
|
|
592
|
+
return cache[key]();
|
|
593
|
+
},
|
|
594
|
+
set() {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
weakmap.set(instance, proxy);
|
|
599
|
+
return proxy;
|
|
600
|
+
}
|
|
601
|
+
__name(useIV, "useIV");
|
|
540
602
|
// Annotate the CommonJS export names for ESM import in node:
|
|
541
603
|
0 && (module.exports = {
|
|
542
604
|
Shallow,
|
|
@@ -548,9 +610,12 @@ __name(WatchEffect, "WatchEffect");
|
|
|
548
610
|
getR,
|
|
549
611
|
getRaw,
|
|
550
612
|
getV,
|
|
613
|
+
hasI,
|
|
551
614
|
markRaw,
|
|
552
615
|
phecdaSymbol,
|
|
553
616
|
useEvent,
|
|
617
|
+
useIR,
|
|
618
|
+
useIV,
|
|
554
619
|
usePhecda,
|
|
555
620
|
useR,
|
|
556
621
|
useRaw,
|
package/dist/index.mjs
CHANGED
|
@@ -499,6 +499,65 @@ function WatchEffect(option) {
|
|
|
499
499
|
};
|
|
500
500
|
}
|
|
501
501
|
__name(WatchEffect, "WatchEffect");
|
|
502
|
+
|
|
503
|
+
// src/lib.ts
|
|
504
|
+
import { bindMethod as bindMethod3, getParamtypes, getTag as getTag3, invokeInit, invokeUnmount } from "phecda-web";
|
|
505
|
+
import { getCurrentInstance as getCurrentInstance2, inject as inject2, onBeforeUnmount as onBeforeUnmount2, provide, reactive as reactive2, toRef as toRef2 } from "vue";
|
|
506
|
+
function hasI(model) {
|
|
507
|
+
const tag = getTag3(model);
|
|
508
|
+
const injectKey = `phecda-vue:lib ${tag.toString()}`;
|
|
509
|
+
return !!inject2(injectKey);
|
|
510
|
+
}
|
|
511
|
+
__name(hasI, "hasI");
|
|
512
|
+
function useIR(model, forceProvide = false) {
|
|
513
|
+
const tag = getTag3(model);
|
|
514
|
+
const instance = getCurrentInstance2();
|
|
515
|
+
if (!instance["phecda-vue"]) instance["phecda-vue"] = /* @__PURE__ */ new WeakMap();
|
|
516
|
+
const modelMap = instance["phecda-vue"];
|
|
517
|
+
const injectKey = `phecda-vue:lib ${tag.toString()}`;
|
|
518
|
+
let existModule = modelMap.get(model) || inject2(injectKey);
|
|
519
|
+
if (!existModule || forceProvide) {
|
|
520
|
+
const data = {
|
|
521
|
+
// keep class name
|
|
522
|
+
[model.name]: class extends model {
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
const paramtypes = getParamtypes(model) || [];
|
|
526
|
+
existModule = bindMethod3(reactive2(new data[model.name](...paramtypes.map((param) => useIR(param)))));
|
|
527
|
+
invokeInit(existModule);
|
|
528
|
+
provide(injectKey, existModule);
|
|
529
|
+
modelMap.set(model, existModule);
|
|
530
|
+
onBeforeUnmount2(() => invokeUnmount(existModule));
|
|
531
|
+
return existModule;
|
|
532
|
+
} else {
|
|
533
|
+
return existModule;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
__name(useIR, "useIR");
|
|
537
|
+
var weakmap = /* @__PURE__ */ new WeakMap();
|
|
538
|
+
function useIV(model, forceProvide = false) {
|
|
539
|
+
const instance = useIR(model, forceProvide);
|
|
540
|
+
if (weakmap.has(instance)) return weakmap.get(instance);
|
|
541
|
+
const cache = {};
|
|
542
|
+
const proxy = new Proxy(instance, {
|
|
543
|
+
get(target, key) {
|
|
544
|
+
if (typeof target[key] === "function") return target[key];
|
|
545
|
+
if (target[key]?.__v_skip) return target[key];
|
|
546
|
+
const cacheRef = cache[key];
|
|
547
|
+
if (cacheRef && cacheRef.r) return cacheRef();
|
|
548
|
+
cache[key] = createSharedReactive(() => {
|
|
549
|
+
return toRef2(target, key);
|
|
550
|
+
});
|
|
551
|
+
return cache[key]();
|
|
552
|
+
},
|
|
553
|
+
set() {
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
weakmap.set(instance, proxy);
|
|
558
|
+
return proxy;
|
|
559
|
+
}
|
|
560
|
+
__name(useIV, "useIV");
|
|
502
561
|
export {
|
|
503
562
|
Shallow,
|
|
504
563
|
VuePhecda,
|
|
@@ -509,9 +568,12 @@ export {
|
|
|
509
568
|
getR,
|
|
510
569
|
getRaw,
|
|
511
570
|
getV,
|
|
571
|
+
hasI,
|
|
512
572
|
markRaw,
|
|
513
573
|
phecdaSymbol,
|
|
514
574
|
useEvent,
|
|
575
|
+
useIR,
|
|
576
|
+
useIV,
|
|
515
577
|
usePhecda,
|
|
516
578
|
useR,
|
|
517
579
|
useRaw,
|