phecda-vue 4.0.8 → 5.1.0
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 +63 -6
- package/dist/index.mjs +61 -7
- package/package.json +2 -2
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,
|
|
@@ -428,7 +431,7 @@ function usePhecda() {
|
|
|
428
431
|
return cacheMap.get(activePhecda);
|
|
429
432
|
}
|
|
430
433
|
__name(usePhecda, "usePhecda");
|
|
431
|
-
function
|
|
434
|
+
function setMetaToComponent(model) {
|
|
432
435
|
if (USE_DEVTOOLS) {
|
|
433
436
|
const currentInstance = (0, import_vue3.getCurrentInstance)();
|
|
434
437
|
if (currentInstance && currentInstance.proxy) {
|
|
@@ -439,7 +442,7 @@ function setStateToComponent(model) {
|
|
|
439
442
|
}
|
|
440
443
|
}
|
|
441
444
|
}
|
|
442
|
-
__name(
|
|
445
|
+
__name(setMetaToComponent, "setMetaToComponent");
|
|
443
446
|
function getPhecda(phecda) {
|
|
444
447
|
const activePhecda = phecda || (0, import_phecda_web2.getDefaultPhecda)("vue");
|
|
445
448
|
if (!activePhecda) throw new Error("[phecda-vue]: manually inject the phecda instance if there is no default phecda");
|
|
@@ -459,7 +462,7 @@ function useEvent(eventName, cb) {
|
|
|
459
462
|
}
|
|
460
463
|
__name(useEvent, "useEvent");
|
|
461
464
|
function useR(model) {
|
|
462
|
-
|
|
465
|
+
setMetaToComponent(model);
|
|
463
466
|
return usePhecda().init(model);
|
|
464
467
|
}
|
|
465
468
|
__name(useR, "useR");
|
|
@@ -468,7 +471,7 @@ function getR(model, phecda) {
|
|
|
468
471
|
}
|
|
469
472
|
__name(getR, "getR");
|
|
470
473
|
function useV(model) {
|
|
471
|
-
|
|
474
|
+
setMetaToComponent(model);
|
|
472
475
|
const instance = usePhecda().init(model);
|
|
473
476
|
if (cacheMap.has(instance)) return cacheMap.get(instance);
|
|
474
477
|
const cache = {};
|
|
@@ -524,9 +527,8 @@ function Shallow(model) {
|
|
|
524
527
|
__name(Shallow, "Shallow");
|
|
525
528
|
function WatchEffect(option) {
|
|
526
529
|
return (proto, key) => {
|
|
527
|
-
(0, import_phecda_web3.setStateKey)(proto, key);
|
|
528
530
|
let stopHandler;
|
|
529
|
-
(0, import_phecda_web3.
|
|
531
|
+
(0, import_phecda_web3.setMeta)(proto, key, void 0, {
|
|
530
532
|
init(instance) {
|
|
531
533
|
if (typeof instance[key] !== "function") throw new Error("WatchEffect must decorate function");
|
|
532
534
|
stopHandler = (0, import_vue4.watchEffect)(instance[key].bind(instance), option);
|
|
@@ -538,6 +540,58 @@ function WatchEffect(option) {
|
|
|
538
540
|
};
|
|
539
541
|
}
|
|
540
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 injectKey = `phecda-vue:lib ${tag.toString()}`;
|
|
556
|
+
let existModule = (0, import_vue5.inject)(injectKey);
|
|
557
|
+
if (!existModule || forceProvide) {
|
|
558
|
+
const data = {
|
|
559
|
+
// keep class name
|
|
560
|
+
[model.name]: class extends model {
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
existModule = (0, import_phecda_web4.bindMethod)((0, import_vue5.reactive)(new data[model.name]()));
|
|
564
|
+
(0, import_vue5.provide)(injectKey, existModule);
|
|
565
|
+
return existModule;
|
|
566
|
+
} else {
|
|
567
|
+
return existModule;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
__name(useIR, "useIR");
|
|
571
|
+
var weakmap = /* @__PURE__ */ new WeakMap();
|
|
572
|
+
function useIV(model, forceProvide = false) {
|
|
573
|
+
const instance = useIR(model, forceProvide);
|
|
574
|
+
if (weakmap.has(instance)) return weakmap.get(instance);
|
|
575
|
+
const cache = {};
|
|
576
|
+
const proxy = new Proxy(instance, {
|
|
577
|
+
get(target, key) {
|
|
578
|
+
if (typeof target[key] === "function") return target[key];
|
|
579
|
+
if (target[key]?.__v_skip) return target[key];
|
|
580
|
+
const cacheRef = cache[key];
|
|
581
|
+
if (cacheRef && cacheRef.r) return cacheRef();
|
|
582
|
+
cache[key] = createSharedReactive(() => {
|
|
583
|
+
return (0, import_vue5.toRef)(target, key);
|
|
584
|
+
});
|
|
585
|
+
return cache[key]();
|
|
586
|
+
},
|
|
587
|
+
set() {
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
weakmap.set(instance, proxy);
|
|
592
|
+
return proxy;
|
|
593
|
+
}
|
|
594
|
+
__name(useIV, "useIV");
|
|
541
595
|
// Annotate the CommonJS export names for ESM import in node:
|
|
542
596
|
0 && (module.exports = {
|
|
543
597
|
Shallow,
|
|
@@ -549,9 +603,12 @@ __name(WatchEffect, "WatchEffect");
|
|
|
549
603
|
getR,
|
|
550
604
|
getRaw,
|
|
551
605
|
getV,
|
|
606
|
+
hasI,
|
|
552
607
|
markRaw,
|
|
553
608
|
phecdaSymbol,
|
|
554
609
|
useEvent,
|
|
610
|
+
useIR,
|
|
611
|
+
useIV,
|
|
555
612
|
usePhecda,
|
|
556
613
|
useR,
|
|
557
614
|
useRaw,
|
package/dist/index.mjs
CHANGED
|
@@ -390,7 +390,7 @@ function usePhecda() {
|
|
|
390
390
|
return cacheMap.get(activePhecda);
|
|
391
391
|
}
|
|
392
392
|
__name(usePhecda, "usePhecda");
|
|
393
|
-
function
|
|
393
|
+
function setMetaToComponent(model) {
|
|
394
394
|
if (USE_DEVTOOLS) {
|
|
395
395
|
const currentInstance = getCurrentInstance();
|
|
396
396
|
if (currentInstance && currentInstance.proxy) {
|
|
@@ -401,7 +401,7 @@ function setStateToComponent(model) {
|
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
|
-
__name(
|
|
404
|
+
__name(setMetaToComponent, "setMetaToComponent");
|
|
405
405
|
function getPhecda(phecda) {
|
|
406
406
|
const activePhecda = phecda || getDefaultPhecda("vue");
|
|
407
407
|
if (!activePhecda) throw new Error("[phecda-vue]: manually inject the phecda instance if there is no default phecda");
|
|
@@ -421,7 +421,7 @@ function useEvent(eventName, cb) {
|
|
|
421
421
|
}
|
|
422
422
|
__name(useEvent, "useEvent");
|
|
423
423
|
function useR(model) {
|
|
424
|
-
|
|
424
|
+
setMetaToComponent(model);
|
|
425
425
|
return usePhecda().init(model);
|
|
426
426
|
}
|
|
427
427
|
__name(useR, "useR");
|
|
@@ -430,7 +430,7 @@ function getR(model, phecda) {
|
|
|
430
430
|
}
|
|
431
431
|
__name(getR, "getR");
|
|
432
432
|
function useV(model) {
|
|
433
|
-
|
|
433
|
+
setMetaToComponent(model);
|
|
434
434
|
const instance = usePhecda().init(model);
|
|
435
435
|
if (cacheMap.has(instance)) return cacheMap.get(instance);
|
|
436
436
|
const cache = {};
|
|
@@ -478,7 +478,7 @@ function getV(model, phecda) {
|
|
|
478
478
|
__name(getV, "getV");
|
|
479
479
|
|
|
480
480
|
// src/decorator.ts
|
|
481
|
-
import { set,
|
|
481
|
+
import { set, setMeta } from "phecda-web";
|
|
482
482
|
import { watchEffect } from "vue";
|
|
483
483
|
function Shallow(model) {
|
|
484
484
|
set(model.prototype, "shallow", true);
|
|
@@ -486,9 +486,8 @@ function Shallow(model) {
|
|
|
486
486
|
__name(Shallow, "Shallow");
|
|
487
487
|
function WatchEffect(option) {
|
|
488
488
|
return (proto, key) => {
|
|
489
|
-
setStateKey(proto, key);
|
|
490
489
|
let stopHandler;
|
|
491
|
-
|
|
490
|
+
setMeta(proto, key, void 0, {
|
|
492
491
|
init(instance) {
|
|
493
492
|
if (typeof instance[key] !== "function") throw new Error("WatchEffect must decorate function");
|
|
494
493
|
stopHandler = watchEffect(instance[key].bind(instance), option);
|
|
@@ -500,6 +499,58 @@ function WatchEffect(option) {
|
|
|
500
499
|
};
|
|
501
500
|
}
|
|
502
501
|
__name(WatchEffect, "WatchEffect");
|
|
502
|
+
|
|
503
|
+
// src/lib.ts
|
|
504
|
+
import { bindMethod as bindMethod3, getTag as getTag3 } from "phecda-web";
|
|
505
|
+
import { inject as inject2, 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 injectKey = `phecda-vue:lib ${tag.toString()}`;
|
|
515
|
+
let existModule = inject2(injectKey);
|
|
516
|
+
if (!existModule || forceProvide) {
|
|
517
|
+
const data = {
|
|
518
|
+
// keep class name
|
|
519
|
+
[model.name]: class extends model {
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
existModule = bindMethod3(reactive2(new data[model.name]()));
|
|
523
|
+
provide(injectKey, existModule);
|
|
524
|
+
return existModule;
|
|
525
|
+
} else {
|
|
526
|
+
return existModule;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
__name(useIR, "useIR");
|
|
530
|
+
var weakmap = /* @__PURE__ */ new WeakMap();
|
|
531
|
+
function useIV(model, forceProvide = false) {
|
|
532
|
+
const instance = useIR(model, forceProvide);
|
|
533
|
+
if (weakmap.has(instance)) return weakmap.get(instance);
|
|
534
|
+
const cache = {};
|
|
535
|
+
const proxy = new Proxy(instance, {
|
|
536
|
+
get(target, key) {
|
|
537
|
+
if (typeof target[key] === "function") return target[key];
|
|
538
|
+
if (target[key]?.__v_skip) return target[key];
|
|
539
|
+
const cacheRef = cache[key];
|
|
540
|
+
if (cacheRef && cacheRef.r) return cacheRef();
|
|
541
|
+
cache[key] = createSharedReactive(() => {
|
|
542
|
+
return toRef2(target, key);
|
|
543
|
+
});
|
|
544
|
+
return cache[key]();
|
|
545
|
+
},
|
|
546
|
+
set() {
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
weakmap.set(instance, proxy);
|
|
551
|
+
return proxy;
|
|
552
|
+
}
|
|
553
|
+
__name(useIV, "useIV");
|
|
503
554
|
export {
|
|
504
555
|
Shallow,
|
|
505
556
|
VuePhecda,
|
|
@@ -510,9 +561,12 @@ export {
|
|
|
510
561
|
getR,
|
|
511
562
|
getRaw,
|
|
512
563
|
getV,
|
|
564
|
+
hasI,
|
|
513
565
|
markRaw,
|
|
514
566
|
phecdaSymbol,
|
|
515
567
|
useEvent,
|
|
568
|
+
useIR,
|
|
569
|
+
useIV,
|
|
516
570
|
usePhecda,
|
|
517
571
|
useR,
|
|
518
572
|
useRaw,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-vue",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "provide phecda function to vue",
|
|
5
5
|
"author": "fgsreally",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@vue/devtools-api": "^6.6.3",
|
|
20
20
|
"vue": "^3.2.45",
|
|
21
|
-
"phecda-web": "
|
|
21
|
+
"phecda-web": "3.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@vue/test-utils": "^2.4.6",
|