@viewfly/core 2.2.0 → 3.0.0-alpha.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/base/_api.d.ts +0 -1
- package/dist/base/component.d.ts +19 -7
- package/dist/base/context.d.ts +70 -0
- package/dist/base/jsx-element.d.ts +1 -1
- package/dist/base/lifecycle.d.ts +24 -7
- package/dist/base/ref.d.ts +36 -30
- package/dist/base/types.d.ts +4 -7
- package/dist/index.d.ts +0 -1
- package/dist/index.esm.js +344 -285
- package/dist/index.js +1034 -416
- package/dist/reactive/_api.d.ts +2 -0
- package/dist/reactive/computed.d.ts +7 -1
- package/dist/reactive/reactive.d.ts +52 -0
- package/dist/reactive/watch-effect.d.ts +7 -0
- package/dist/reactive/watch.d.ts +8 -1
- package/package.json +8 -8
- package/dist/base/memo.d.ts +0 -8
- package/dist/signals/_api.d.ts +0 -3
- package/dist/signals/derived.d.ts +0 -9
- package/dist/signals/effect.d.ts +0 -22
- /package/dist/{signals → reactive}/signal.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -442,12 +442,17 @@ var Type = Function;
|
|
|
442
442
|
//#endregion
|
|
443
443
|
//#region src/base/lifecycle.ts
|
|
444
444
|
/**
|
|
445
|
-
*
|
|
446
|
-
* @param callback
|
|
445
|
+
* 当组件挂载后调用回调函数
|
|
446
|
+
* @param callback 回调函数
|
|
447
|
+
* @returns 一个函数,用于停止监听
|
|
448
|
+
* @example
|
|
447
449
|
* ```tsx
|
|
448
450
|
* function App() {
|
|
449
|
-
*
|
|
451
|
+
* onMounted(() => {
|
|
450
452
|
* console.log('App mounted!')
|
|
453
|
+
* return () => {
|
|
454
|
+
* console.log('destroy prev mount!')
|
|
455
|
+
* }
|
|
451
456
|
* })
|
|
452
457
|
* return () => <div>...</div>
|
|
453
458
|
* }
|
|
@@ -459,8 +464,10 @@ function onMounted(callback) {
|
|
|
459
464
|
component.mountCallbacks.push(callback);
|
|
460
465
|
}
|
|
461
466
|
/**
|
|
462
|
-
*
|
|
463
|
-
* @param callback
|
|
467
|
+
* 当组件视图更新后调用回调函数
|
|
468
|
+
* @param callback 回调函数
|
|
469
|
+
* @returns 一个函数,用于停止监听
|
|
470
|
+
* @example
|
|
464
471
|
* ```tsx
|
|
465
472
|
* function App() {
|
|
466
473
|
* onUpdated(() => {
|
|
@@ -483,89 +490,36 @@ function onUpdated(callback) {
|
|
|
483
490
|
};
|
|
484
491
|
}
|
|
485
492
|
/**
|
|
486
|
-
*
|
|
487
|
-
* @param callback
|
|
488
|
-
|
|
489
|
-
function onUnmounted(callback) {
|
|
490
|
-
const component = getSetupContext();
|
|
491
|
-
if (!component.unmountedCallbacks) component.unmountedCallbacks = [];
|
|
492
|
-
component.unmountedCallbacks.push(callback);
|
|
493
|
-
}
|
|
494
|
-
//#endregion
|
|
495
|
-
//#region src/base/ref.ts
|
|
496
|
-
var DynamicRef = class {
|
|
497
|
-
unBindMap = /* @__PURE__ */ new Map();
|
|
498
|
-
targetCaches = /* @__PURE__ */ new Set();
|
|
499
|
-
constructor(callback) {
|
|
500
|
-
this.callback = callback;
|
|
501
|
-
}
|
|
502
|
-
bind(value) {
|
|
503
|
-
if (typeof value !== "object" || value === null) return;
|
|
504
|
-
if (this.targetCaches.has(value)) return;
|
|
505
|
-
const unBindFn = this.callback(value);
|
|
506
|
-
if (typeof unBindFn === "function") this.unBindMap.set(value, unBindFn);
|
|
507
|
-
this.targetCaches.add(value);
|
|
508
|
-
}
|
|
509
|
-
unBind(value) {
|
|
510
|
-
this.targetCaches.delete(value);
|
|
511
|
-
const unBindFn = this.unBindMap.get(value);
|
|
512
|
-
this.unBindMap.delete(value);
|
|
513
|
-
if (typeof unBindFn === "function") unBindFn();
|
|
514
|
-
}
|
|
515
|
-
};
|
|
516
|
-
/**
|
|
517
|
-
* 用于节点渲染完成时获取 DOM 节点
|
|
518
|
-
* @param callback 获取 DOM 节点的回调函数
|
|
493
|
+
* 当组件销毁后调用回调函数
|
|
494
|
+
* @param callback 回调函数
|
|
495
|
+
* @returns 一个函数,用于停止监听
|
|
519
496
|
* @example
|
|
520
497
|
* ```tsx
|
|
521
498
|
* function App() {
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
* // do something...
|
|
525
|
-
* }
|
|
526
|
-
* node.addEventListener('click', fn)
|
|
527
|
-
* return () => {
|
|
528
|
-
* node.removeEventListener('click', fn)
|
|
529
|
-
* }
|
|
499
|
+
* onUnmounted(() => {
|
|
500
|
+
* console.log('App unmounted!')
|
|
530
501
|
* })
|
|
531
|
-
* return () =>
|
|
532
|
-
* return <div ref={ref}>xxx</div>
|
|
533
|
-
* }
|
|
502
|
+
* return () => <div>...</div>
|
|
534
503
|
* }
|
|
535
504
|
* ```
|
|
536
505
|
*/
|
|
537
|
-
function
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
get current() {
|
|
542
|
-
return this._current;
|
|
543
|
-
}
|
|
544
|
-
_current = null;
|
|
545
|
-
constructor() {
|
|
546
|
-
super((v) => {
|
|
547
|
-
this._current = v;
|
|
548
|
-
return () => {
|
|
549
|
-
this._current = null;
|
|
550
|
-
};
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
function createRef() {
|
|
555
|
-
return new StaticRef();
|
|
506
|
+
function onUnmounted(callback) {
|
|
507
|
+
const component = getSetupContext();
|
|
508
|
+
if (!component.unmountedCallbacks) component.unmountedCallbacks = [];
|
|
509
|
+
component.unmountedCallbacks.push(callback);
|
|
556
510
|
}
|
|
557
511
|
//#endregion
|
|
558
512
|
//#region src/reactive/_help.ts
|
|
559
|
-
var toStr = Object.prototype.toString;
|
|
560
|
-
function getStringType(v) {
|
|
561
|
-
return toStr.call(v);
|
|
513
|
+
var toStr$1 = Object.prototype.toString;
|
|
514
|
+
function getStringType$1(v) {
|
|
515
|
+
return toStr$1.call(v);
|
|
562
516
|
}
|
|
563
|
-
function isArray(v) {
|
|
517
|
+
function isArray$1(v) {
|
|
564
518
|
return Array.isArray(v);
|
|
565
519
|
}
|
|
566
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
567
|
-
function hasOwn(target, key) {
|
|
568
|
-
return hasOwnProperty.call(target, key);
|
|
520
|
+
var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
521
|
+
function hasOwn$1(target, key) {
|
|
522
|
+
return hasOwnProperty$1.call(target, key);
|
|
569
523
|
}
|
|
570
524
|
//#endregion
|
|
571
525
|
//#region src/base/dep.ts
|
|
@@ -579,24 +533,24 @@ var Dep = class {
|
|
|
579
533
|
this.destroyCallbacks = [];
|
|
580
534
|
}
|
|
581
535
|
};
|
|
582
|
-
var deps = [];
|
|
536
|
+
var deps$1 = [];
|
|
583
537
|
function getDepContext() {
|
|
584
|
-
return deps.at(-1);
|
|
538
|
+
return deps$1.at(-1);
|
|
585
539
|
}
|
|
586
540
|
function pushDepContext(dep) {
|
|
587
|
-
deps.push(dep);
|
|
541
|
+
deps$1.push(dep);
|
|
588
542
|
}
|
|
589
543
|
function popDepContext() {
|
|
590
|
-
deps.pop();
|
|
544
|
+
deps$1.pop();
|
|
591
545
|
}
|
|
592
546
|
//#endregion
|
|
593
547
|
//#region src/reactive/effect.ts
|
|
594
|
-
var subscribers = /* @__PURE__ */ new WeakMap();
|
|
595
|
-
function getSubscriber(target) {
|
|
596
|
-
let subscriber = subscribers.get(target);
|
|
548
|
+
var subscribers$1 = /* @__PURE__ */ new WeakMap();
|
|
549
|
+
function getSubscriber$1(target) {
|
|
550
|
+
let subscriber = subscribers$1.get(target);
|
|
597
551
|
if (!subscriber) {
|
|
598
552
|
subscriber = /* @__PURE__ */ new Map();
|
|
599
|
-
subscribers.set(target, subscriber);
|
|
553
|
+
subscribers$1.set(target, subscriber);
|
|
600
554
|
}
|
|
601
555
|
return subscriber;
|
|
602
556
|
}
|
|
@@ -613,11 +567,11 @@ var TriggerOpTypes = /* @__PURE__ */ function(TriggerOpTypes) {
|
|
|
613
567
|
TriggerOpTypes["Clear"] = "Clear";
|
|
614
568
|
return TriggerOpTypes;
|
|
615
569
|
}({});
|
|
616
|
-
var unKnownKey = Symbol("unKnownKey");
|
|
617
|
-
function track(target, type, key = unKnownKey) {
|
|
570
|
+
var unKnownKey$1 = Symbol("unKnownKey");
|
|
571
|
+
function track(target, type, key = unKnownKey$1) {
|
|
618
572
|
const dep = getDepContext();
|
|
619
573
|
if (dep) {
|
|
620
|
-
const subscriber = getSubscriber(target);
|
|
574
|
+
const subscriber = getSubscriber$1(target);
|
|
621
575
|
let record = subscriber.get(type);
|
|
622
576
|
if (!record) {
|
|
623
577
|
record = /* @__PURE__ */ new Map();
|
|
@@ -638,31 +592,31 @@ function track(target, type, key = unKnownKey) {
|
|
|
638
592
|
}
|
|
639
593
|
}
|
|
640
594
|
}
|
|
641
|
-
function runEffect(key, record) {
|
|
595
|
+
function runEffect$1(key, record) {
|
|
642
596
|
if (!record) return;
|
|
643
597
|
const effects = record.get(key);
|
|
644
598
|
if (effects) [...effects].forEach((i) => i.effect());
|
|
645
599
|
}
|
|
646
|
-
function trigger(target, type, key = unKnownKey) {
|
|
647
|
-
const subscriber = getSubscriber(target);
|
|
600
|
+
function trigger(target, type, key = unKnownKey$1) {
|
|
601
|
+
const subscriber = getSubscriber$1(target);
|
|
648
602
|
if (subscriber) switch (type) {
|
|
649
603
|
case TriggerOpTypes.Set:
|
|
650
|
-
if (isArray(target)) runEffect(unKnownKey, subscriber.get(TrackOpTypes.Iterate));
|
|
651
|
-
runEffect(key, subscriber.get(TrackOpTypes.Get));
|
|
652
|
-
runEffect(key, subscriber.get(TrackOpTypes.Has));
|
|
604
|
+
if (isArray$1(target)) runEffect$1(unKnownKey$1, subscriber.get(TrackOpTypes.Iterate));
|
|
605
|
+
runEffect$1(key, subscriber.get(TrackOpTypes.Get));
|
|
606
|
+
runEffect$1(key, subscriber.get(TrackOpTypes.Has));
|
|
653
607
|
break;
|
|
654
608
|
case TriggerOpTypes.Add:
|
|
655
609
|
case TriggerOpTypes.Clear:
|
|
656
610
|
case TriggerOpTypes.Delete:
|
|
657
|
-
runEffect(unKnownKey, subscriber.get(TrackOpTypes.Iterate));
|
|
658
|
-
runEffect(key, subscriber.get(TrackOpTypes.Has));
|
|
659
|
-
runEffect(key, subscriber.get(TrackOpTypes.Get));
|
|
611
|
+
runEffect$1(unKnownKey$1, subscriber.get(TrackOpTypes.Iterate));
|
|
612
|
+
runEffect$1(key, subscriber.get(TrackOpTypes.Has));
|
|
613
|
+
runEffect$1(key, subscriber.get(TrackOpTypes.Get));
|
|
660
614
|
break;
|
|
661
615
|
}
|
|
662
616
|
}
|
|
663
617
|
//#endregion
|
|
664
618
|
//#region src/reactive/iterable-iterator.ts
|
|
665
|
-
function createIterableIterator(wrapper) {
|
|
619
|
+
function createIterableIterator$1(wrapper) {
|
|
666
620
|
return {
|
|
667
621
|
*entries() {
|
|
668
622
|
const target = toRaw(this);
|
|
@@ -683,19 +637,19 @@ function createIterableIterator(wrapper) {
|
|
|
683
637
|
}
|
|
684
638
|
//#endregion
|
|
685
639
|
//#region src/reactive/array-handlers.ts
|
|
686
|
-
function applyPredicateMethod(self, methodName, predicate, wrapper, thisArg) {
|
|
640
|
+
function applyPredicateMethod$1(self, methodName, predicate, wrapper, thisArg) {
|
|
687
641
|
const target = toRaw(self);
|
|
688
642
|
track(target, TrackOpTypes.Iterate);
|
|
689
643
|
return target[methodName]((value, index, array) => {
|
|
690
644
|
return predicate.call(target, wrapper(value), index, array);
|
|
691
645
|
}, thisArg);
|
|
692
646
|
}
|
|
693
|
-
function applySearchMethod(self, methodName, args) {
|
|
647
|
+
function applySearchMethod$1(self, methodName, args) {
|
|
694
648
|
const target = toRaw(self);
|
|
695
649
|
track(target, TrackOpTypes.Iterate);
|
|
696
650
|
return target[methodName](...args.map(toRaw));
|
|
697
651
|
}
|
|
698
|
-
function createArrayHandlers(wrapper) {
|
|
652
|
+
function createArrayHandlers$1(wrapper) {
|
|
699
653
|
return {
|
|
700
654
|
concat(...items) {
|
|
701
655
|
const target = toRaw(this);
|
|
@@ -703,31 +657,31 @@ function createArrayHandlers(wrapper) {
|
|
|
703
657
|
return target.concat(...items);
|
|
704
658
|
},
|
|
705
659
|
every(predicate, thisArg) {
|
|
706
|
-
return applyPredicateMethod(this, "every", predicate, wrapper, thisArg);
|
|
660
|
+
return applyPredicateMethod$1(this, "every", predicate, wrapper, thisArg);
|
|
707
661
|
},
|
|
708
662
|
filter(predicate, thisArg) {
|
|
709
|
-
return applyPredicateMethod(this, "filter", predicate, wrapper, thisArg);
|
|
663
|
+
return applyPredicateMethod$1(this, "filter", predicate, wrapper, thisArg);
|
|
710
664
|
},
|
|
711
665
|
find(predicate, thisArg) {
|
|
712
|
-
return applyPredicateMethod(this, "find", predicate, wrapper, thisArg);
|
|
666
|
+
return applyPredicateMethod$1(this, "find", predicate, wrapper, thisArg);
|
|
713
667
|
},
|
|
714
668
|
findIndex(predicate, thisArg) {
|
|
715
|
-
return applyPredicateMethod(this, "findIndex", predicate, wrapper, thisArg);
|
|
669
|
+
return applyPredicateMethod$1(this, "findIndex", predicate, wrapper, thisArg);
|
|
716
670
|
},
|
|
717
671
|
findLast(predicate, thisArg) {
|
|
718
|
-
return applyPredicateMethod(this, "findLast", predicate, wrapper, thisArg);
|
|
672
|
+
return applyPredicateMethod$1(this, "findLast", predicate, wrapper, thisArg);
|
|
719
673
|
},
|
|
720
674
|
findLastIndex(predicate, thisArg) {
|
|
721
|
-
return applyPredicateMethod(this, "findLastIndex", predicate, wrapper, thisArg);
|
|
675
|
+
return applyPredicateMethod$1(this, "findLastIndex", predicate, wrapper, thisArg);
|
|
722
676
|
},
|
|
723
677
|
forEach(callbackfn, thisArg) {
|
|
724
|
-
return applyPredicateMethod(this, "forEach", callbackfn, wrapper, thisArg);
|
|
678
|
+
return applyPredicateMethod$1(this, "forEach", callbackfn, wrapper, thisArg);
|
|
725
679
|
},
|
|
726
680
|
includes(...args) {
|
|
727
|
-
return applySearchMethod(this, "includes", args);
|
|
681
|
+
return applySearchMethod$1(this, "includes", args);
|
|
728
682
|
},
|
|
729
683
|
indexOf(...args) {
|
|
730
|
-
return applySearchMethod(this, "indexOf", args);
|
|
684
|
+
return applySearchMethod$1(this, "indexOf", args);
|
|
731
685
|
},
|
|
732
686
|
join(separator) {
|
|
733
687
|
const target = toRaw(this);
|
|
@@ -735,10 +689,10 @@ function createArrayHandlers(wrapper) {
|
|
|
735
689
|
return target.join(separator);
|
|
736
690
|
},
|
|
737
691
|
lastIndexOf(...args) {
|
|
738
|
-
return applySearchMethod(this, "lastIndexOf", args);
|
|
692
|
+
return applySearchMethod$1(this, "lastIndexOf", args);
|
|
739
693
|
},
|
|
740
694
|
map(callbackFn, thisArg) {
|
|
741
|
-
return applyPredicateMethod(this, "map", callbackFn, wrapper, thisArg);
|
|
695
|
+
return applyPredicateMethod$1(this, "map", callbackFn, wrapper, thisArg);
|
|
742
696
|
},
|
|
743
697
|
pop() {
|
|
744
698
|
const target = toRaw(this);
|
|
@@ -772,7 +726,7 @@ function createArrayHandlers(wrapper) {
|
|
|
772
726
|
return target.shift();
|
|
773
727
|
},
|
|
774
728
|
some(predicate, thisArg) {
|
|
775
|
-
return applyPredicateMethod(this, "some", predicate, wrapper, thisArg);
|
|
729
|
+
return applyPredicateMethod$1(this, "some", predicate, wrapper, thisArg);
|
|
776
730
|
},
|
|
777
731
|
splice(start, deleteCount) {
|
|
778
732
|
const target = toRaw(this);
|
|
@@ -804,12 +758,12 @@ function createArrayHandlers(wrapper) {
|
|
|
804
758
|
[Symbol.iterator]() {
|
|
805
759
|
return this.values();
|
|
806
760
|
},
|
|
807
|
-
...createIterableIterator(wrapper)
|
|
761
|
+
...createIterableIterator$1(wrapper)
|
|
808
762
|
};
|
|
809
763
|
}
|
|
810
764
|
//#endregion
|
|
811
765
|
//#region src/reactive/map-handlers.ts
|
|
812
|
-
function createMapHandlers(wrapper) {
|
|
766
|
+
function createMapHandlers$1(wrapper) {
|
|
813
767
|
return {
|
|
814
768
|
get(key) {
|
|
815
769
|
const target = toRaw(this);
|
|
@@ -853,12 +807,12 @@ function createMapHandlers(wrapper) {
|
|
|
853
807
|
[Symbol.iterator]() {
|
|
854
808
|
return this.entries();
|
|
855
809
|
},
|
|
856
|
-
...createIterableIterator(wrapper)
|
|
810
|
+
...createIterableIterator$1(wrapper)
|
|
857
811
|
};
|
|
858
812
|
}
|
|
859
813
|
//#endregion
|
|
860
814
|
//#region src/reactive/set-handlers.ts
|
|
861
|
-
function createSetHandlers(wrapper) {
|
|
815
|
+
function createSetHandlers$1(wrapper) {
|
|
862
816
|
return {
|
|
863
817
|
add(value) {
|
|
864
818
|
const target = toRaw(this);
|
|
@@ -900,26 +854,57 @@ function createSetHandlers(wrapper) {
|
|
|
900
854
|
[Symbol.iterator]() {
|
|
901
855
|
return this.values();
|
|
902
856
|
},
|
|
903
|
-
...createIterableIterator(wrapper)
|
|
857
|
+
...createIterableIterator$1(wrapper)
|
|
904
858
|
};
|
|
905
859
|
}
|
|
906
860
|
//#endregion
|
|
907
861
|
//#region src/reactive/reactive.ts
|
|
908
|
-
var reactiveErrorFn = makeError("reactive");
|
|
862
|
+
var reactiveErrorFn$1 = makeError("reactive");
|
|
909
863
|
var rawToProxyCache = /* @__PURE__ */ new WeakMap();
|
|
910
864
|
var proxyToRawCache = /* @__PURE__ */ new WeakMap();
|
|
865
|
+
/**
|
|
866
|
+
* 将响应式对象转换为原始对象
|
|
867
|
+
* @param value 响应式对象
|
|
868
|
+
* @returns 原始对象
|
|
869
|
+
* @example
|
|
870
|
+
* ```tsx
|
|
871
|
+
* const obj = reactive({
|
|
872
|
+
* name: 'John',
|
|
873
|
+
* age: 18
|
|
874
|
+
* })
|
|
875
|
+
* console.log(toRaw(obj))
|
|
876
|
+
* ```
|
|
877
|
+
*/
|
|
911
878
|
function toRaw(value) {
|
|
912
879
|
if (proxyToRawCache.has(value)) return proxyToRawCache.get(value);
|
|
913
880
|
return value;
|
|
914
881
|
}
|
|
882
|
+
/**
|
|
883
|
+
* 检查对象是否是响应式对象
|
|
884
|
+
* @param value 要检查的对象
|
|
885
|
+
* @returns 是否是响应式对象
|
|
886
|
+
* @example
|
|
887
|
+
* ```tsx
|
|
888
|
+
* const obj = reactive({
|
|
889
|
+
* name: 'John',
|
|
890
|
+
* age: 18
|
|
891
|
+
* })
|
|
892
|
+
* console.log(isReactive(obj))
|
|
893
|
+
* ```
|
|
894
|
+
*/
|
|
915
895
|
function isReactive(value) {
|
|
916
896
|
return proxyToRawCache.has(value);
|
|
917
897
|
}
|
|
918
|
-
var fromInternalWrite = false;
|
|
898
|
+
var fromInternalWrite$1 = false;
|
|
899
|
+
/**
|
|
900
|
+
* 内部写入,用于避免类型为只读的响应式对象写入报错
|
|
901
|
+
* @param fn 要执行的函数
|
|
902
|
+
* @internal
|
|
903
|
+
*/
|
|
919
904
|
function internalWrite(fn) {
|
|
920
|
-
fromInternalWrite = true;
|
|
905
|
+
fromInternalWrite$1 = true;
|
|
921
906
|
fn();
|
|
922
|
-
fromInternalWrite = false;
|
|
907
|
+
fromInternalWrite$1 = false;
|
|
923
908
|
}
|
|
924
909
|
var ObjectReactiveHandler = class {
|
|
925
910
|
isShallow;
|
|
@@ -929,14 +914,14 @@ var ObjectReactiveHandler = class {
|
|
|
929
914
|
this.isShallow = config.shallow;
|
|
930
915
|
}
|
|
931
916
|
set(target, p, newValue, receiver) {
|
|
932
|
-
if (this.isReadonly && !fromInternalWrite) throw reactiveErrorFn("Object is readonly!");
|
|
917
|
+
if (this.isReadonly && !fromInternalWrite$1) throw reactiveErrorFn$1("Object is readonly!");
|
|
933
918
|
const rawValue = toRaw(newValue);
|
|
934
919
|
const oldValue = target[p];
|
|
935
920
|
const v = this.isShallow ? newValue : rawValue;
|
|
936
921
|
if (oldValue === rawValue) return Reflect.set(target, p, v, receiver);
|
|
937
922
|
const b = Reflect.set(target, p, v, receiver);
|
|
938
|
-
fromInternalWrite = false;
|
|
939
|
-
if (hasOwn(target, p)) trigger(target, TriggerOpTypes.Set, p);
|
|
923
|
+
fromInternalWrite$1 = false;
|
|
924
|
+
if (hasOwn$1(target, p)) trigger(target, TriggerOpTypes.Set, p);
|
|
940
925
|
else trigger(target, TriggerOpTypes.Add, p);
|
|
941
926
|
return b;
|
|
942
927
|
}
|
|
@@ -956,11 +941,11 @@ var ObjectReactiveHandler = class {
|
|
|
956
941
|
return Reflect.ownKeys(target);
|
|
957
942
|
}
|
|
958
943
|
};
|
|
959
|
-
function noReactive(v) {
|
|
944
|
+
function noReactive$1(v) {
|
|
960
945
|
return v;
|
|
961
946
|
}
|
|
962
947
|
var ArrayReactiveHandler = class extends ObjectReactiveHandler {
|
|
963
|
-
interceptors = createArrayHandlers(this.isShallow ? noReactive : reactive);
|
|
948
|
+
interceptors = createArrayHandlers$1(this.isShallow ? noReactive$1 : reactive);
|
|
964
949
|
constructor(config) {
|
|
965
950
|
super(config);
|
|
966
951
|
}
|
|
@@ -970,7 +955,7 @@ var ArrayReactiveHandler = class extends ObjectReactiveHandler {
|
|
|
970
955
|
}
|
|
971
956
|
};
|
|
972
957
|
var MapReactiveHandler = class extends ObjectReactiveHandler {
|
|
973
|
-
interceptors = createMapHandlers(this.isShallow ? noReactive : reactive);
|
|
958
|
+
interceptors = createMapHandlers$1(this.isShallow ? noReactive$1 : reactive);
|
|
974
959
|
constructor(config) {
|
|
975
960
|
super(config);
|
|
976
961
|
}
|
|
@@ -984,7 +969,7 @@ var MapReactiveHandler = class extends ObjectReactiveHandler {
|
|
|
984
969
|
}
|
|
985
970
|
};
|
|
986
971
|
var SetReactiveHandler = class extends ObjectReactiveHandler {
|
|
987
|
-
interceptors = createSetHandlers(this.isShallow ? noReactive : reactive);
|
|
972
|
+
interceptors = createSetHandlers$1(this.isShallow ? noReactive$1 : reactive);
|
|
988
973
|
constructor(config) {
|
|
989
974
|
super(config);
|
|
990
975
|
}
|
|
@@ -1017,11 +1002,34 @@ var readonlyProxyHandler = new ObjectReactiveHandler({
|
|
|
1017
1002
|
shallow: true,
|
|
1018
1003
|
readonly: true
|
|
1019
1004
|
});
|
|
1005
|
+
function createShallowReadonlyProxy(value) {
|
|
1006
|
+
return new Proxy(value, readonlyProxyHandler);
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* 创建一个响应式对象
|
|
1010
|
+
* @param raw 原始对象
|
|
1011
|
+
* @returns 响应式对象
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```tsx
|
|
1014
|
+
* const obj = reactive({
|
|
1015
|
+
* name: 'John',
|
|
1016
|
+
* age: 18,
|
|
1017
|
+
* children: [
|
|
1018
|
+
* {
|
|
1019
|
+
* name: 'Jane',
|
|
1020
|
+
* age: 16
|
|
1021
|
+
* }
|
|
1022
|
+
* ]
|
|
1023
|
+
* })
|
|
1024
|
+
* console.log(obj.name)
|
|
1025
|
+
* console.log(obj.children[0].name)
|
|
1026
|
+
* ```
|
|
1027
|
+
*/
|
|
1020
1028
|
function reactive(raw) {
|
|
1021
1029
|
if (isReactive(raw)) return raw;
|
|
1022
1030
|
let proxy = rawToProxyCache.get(raw);
|
|
1023
1031
|
if (proxy) return proxy;
|
|
1024
|
-
switch (getStringType(raw)) {
|
|
1032
|
+
switch (getStringType$1(raw)) {
|
|
1025
1033
|
case "[object Object]":
|
|
1026
1034
|
proxy = new Proxy(raw, defaultObjectReactiveHandler);
|
|
1027
1035
|
break;
|
|
@@ -1092,21 +1100,104 @@ var TextAtomType = Symbol("Text");
|
|
|
1092
1100
|
var ElementAtomType = Symbol("Element");
|
|
1093
1101
|
var ComponentAtomType = Symbol("Component");
|
|
1094
1102
|
//#endregion
|
|
1095
|
-
//#region src/base/
|
|
1096
|
-
var
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1103
|
+
//#region src/base/ref.ts
|
|
1104
|
+
var refErrorFn$1 = makeError("Ref");
|
|
1105
|
+
/**
|
|
1106
|
+
* 创建一个动态 ref,当 ref 的绑定的元素或组件初始化后,会调用副作用函数,并把元素或组件的实例作为参数传入。
|
|
1107
|
+
* @param effect 用于接收实例的副作用函数,该函数还可以返回一个清理副作用的函数,当元素或组件销毁时调用
|
|
1108
|
+
* @returns 一个函数,用于清理副作用
|
|
1109
|
+
* @example
|
|
1110
|
+
* ```tsx
|
|
1111
|
+
* function App() {
|
|
1112
|
+
* const ref = createDynamicRef<HTMLDivElement>((node) => {
|
|
1113
|
+
* console.log(node)
|
|
1114
|
+
* return () => {
|
|
1115
|
+
* console.log('destroy')
|
|
1116
|
+
* }
|
|
1117
|
+
* })
|
|
1118
|
+
* return () => {
|
|
1119
|
+
* return <div ref={ref}>test</div>
|
|
1120
|
+
* }
|
|
1121
|
+
* }
|
|
1122
|
+
* ```
|
|
1123
|
+
*/
|
|
1124
|
+
function createDynamicRef(effect) {
|
|
1125
|
+
return effect;
|
|
1102
1126
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1127
|
+
/**
|
|
1128
|
+
* 创建一个引用对象,并添加到 JSX 节点上属性上,当组件渲染后,即可通过 .value 获取到绑定节点的实例
|
|
1129
|
+
* - 当绑定到虚拟 DOM 元素节点上时,value 为当前节点的 DOM 元素
|
|
1130
|
+
* - 当绑定到组件节点上时,value 为组件函数返回的对象
|
|
1131
|
+
* @example
|
|
1132
|
+
* ```tsx
|
|
1133
|
+
* function App() {
|
|
1134
|
+
* const ref = createRef<HTMLDivElement>()
|
|
1135
|
+
* onMounted(() => {
|
|
1136
|
+
* console.log(ref.value)
|
|
1137
|
+
* })
|
|
1138
|
+
* return () => {
|
|
1139
|
+
* return <div ref={ref}>...</div>
|
|
1140
|
+
* }
|
|
1141
|
+
* }
|
|
1142
|
+
* ```
|
|
1143
|
+
*/
|
|
1144
|
+
function createRef() {
|
|
1145
|
+
return createShallowReadonlyProxy({ value: null });
|
|
1146
|
+
}
|
|
1147
|
+
function applyRefs(ref, value, refEffects) {
|
|
1148
|
+
if (!ref) return;
|
|
1149
|
+
const refs = toRefs(ref);
|
|
1150
|
+
const length = refs.length;
|
|
1151
|
+
for (let i = 0; i < length; i++) bindRefs(refs[i], value, refEffects);
|
|
1152
|
+
}
|
|
1153
|
+
function updateRefs(ref, value, refEffects) {
|
|
1154
|
+
if (!ref) {
|
|
1155
|
+
refEffects.forEach((fn, oldRef) => {
|
|
1156
|
+
refEffects.delete(oldRef);
|
|
1157
|
+
if (typeof fn === "function") fn();
|
|
1158
|
+
});
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
const newRefs = toRefs(ref);
|
|
1162
|
+
refEffects.forEach((fn, oldRef) => {
|
|
1163
|
+
if (newRefs.includes(oldRef)) return;
|
|
1164
|
+
refEffects.delete(oldRef);
|
|
1165
|
+
if (typeof fn === "function") fn();
|
|
1106
1166
|
});
|
|
1167
|
+
const len = newRefs.length;
|
|
1168
|
+
for (let i = 0; i < len; i++) {
|
|
1169
|
+
const newRef = newRefs[i];
|
|
1170
|
+
if (refEffects.has(newRef)) continue;
|
|
1171
|
+
bindRefs(newRef, value, refEffects);
|
|
1172
|
+
}
|
|
1107
1173
|
}
|
|
1108
|
-
function
|
|
1109
|
-
return
|
|
1174
|
+
function toRefs(ref) {
|
|
1175
|
+
return Array.isArray(ref) ? ref : [ref];
|
|
1176
|
+
}
|
|
1177
|
+
function bindRefs(ref, value, refEffects) {
|
|
1178
|
+
const type = typeof ref;
|
|
1179
|
+
if (type === "function") {
|
|
1180
|
+
const fn = ref(value);
|
|
1181
|
+
refEffects.set(ref, fn);
|
|
1182
|
+
} else if (type === "object") {
|
|
1183
|
+
internalWrite(() => {
|
|
1184
|
+
ref.value = value;
|
|
1185
|
+
});
|
|
1186
|
+
refEffects.set(ref, () => {
|
|
1187
|
+
internalWrite(() => {
|
|
1188
|
+
ref.value = null;
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
} else throw refErrorFn$1("ref must be a function or `Ref<T>` object!");
|
|
1192
|
+
}
|
|
1193
|
+
//#endregion
|
|
1194
|
+
//#region src/base/component.ts
|
|
1195
|
+
var componentSetupStack$1 = [];
|
|
1196
|
+
var componentErrorFn$1 = makeError("component");
|
|
1197
|
+
function getSetupContext(need = true) {
|
|
1198
|
+
const current = componentSetupStack$1[componentSetupStack$1.length - 1];
|
|
1199
|
+
if (!current && need) throw componentErrorFn$1("cannot be called outside the component!");
|
|
1200
|
+
return current;
|
|
1110
1201
|
}
|
|
1111
1202
|
/**
|
|
1112
1203
|
* Viewfly 组件管理类,用于管理组件的生命周期,上下文等
|
|
@@ -1133,9 +1224,9 @@ var Component = class {
|
|
|
1133
1224
|
this._dirty = true;
|
|
1134
1225
|
this._changed = false;
|
|
1135
1226
|
this.isFirstRendering = true;
|
|
1136
|
-
this.refs = null;
|
|
1137
1227
|
this.rawProps = props;
|
|
1138
|
-
this.props =
|
|
1228
|
+
this.props = createShallowReadonlyProxy({ ...props });
|
|
1229
|
+
this.refEffects = /* @__PURE__ */ new Map();
|
|
1139
1230
|
this.listener = new Dep(() => {
|
|
1140
1231
|
this.markAsDirtied();
|
|
1141
1232
|
});
|
|
@@ -1151,25 +1242,19 @@ var Component = class {
|
|
|
1151
1242
|
if (this.parentComponent) this.parentComponent.markAsChanged(this);
|
|
1152
1243
|
}
|
|
1153
1244
|
render(update) {
|
|
1154
|
-
componentSetupStack.push(this);
|
|
1245
|
+
componentSetupStack$1.push(this);
|
|
1155
1246
|
const render = this.type(this.props);
|
|
1156
1247
|
const isRenderFn = typeof render === "function";
|
|
1157
1248
|
this.instance = isRenderFn ? { $render: render } : render;
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
const length = refs.length;
|
|
1168
|
-
for (let i = 0; i < length; i++) refs[i].unBind(this.instance);
|
|
1169
|
-
};
|
|
1170
|
-
});
|
|
1171
|
-
}
|
|
1172
|
-
componentSetupStack.pop();
|
|
1249
|
+
onMounted(() => {
|
|
1250
|
+
applyRefs(this.props.ref, this.instance, this.refEffects);
|
|
1251
|
+
return () => {
|
|
1252
|
+
this.refEffects.forEach((fn) => {
|
|
1253
|
+
if (typeof fn === "function") fn();
|
|
1254
|
+
});
|
|
1255
|
+
};
|
|
1256
|
+
});
|
|
1257
|
+
componentSetupStack$1.pop();
|
|
1173
1258
|
pushDepContext(this.listener);
|
|
1174
1259
|
const template = this.instance.$render();
|
|
1175
1260
|
popDepContext();
|
|
@@ -1179,7 +1264,7 @@ var Component = class {
|
|
|
1179
1264
|
updateProps(newProps) {
|
|
1180
1265
|
const oldProps = this.rawProps;
|
|
1181
1266
|
this.rawProps = newProps;
|
|
1182
|
-
const newRefs =
|
|
1267
|
+
const newRefs = newProps.ref;
|
|
1183
1268
|
comparePropsWithCallbacks(oldProps, newProps, (key) => {
|
|
1184
1269
|
internalWrite(() => {
|
|
1185
1270
|
Reflect.deleteProperty(oldProps, key);
|
|
@@ -1193,22 +1278,7 @@ var Component = class {
|
|
|
1193
1278
|
this.props[key] = value;
|
|
1194
1279
|
});
|
|
1195
1280
|
});
|
|
1196
|
-
|
|
1197
|
-
const len = this.refs.length;
|
|
1198
|
-
for (let i = 0; i < len; i++) {
|
|
1199
|
-
const oldRef = this.refs[i];
|
|
1200
|
-
if (!newRefs.includes(oldRef)) oldRef.unBind(this.instance);
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
const len = newRefs.length;
|
|
1204
|
-
for (let i = 0; i < len; i++) newRefs[i].bind(this.instance);
|
|
1205
|
-
if (len) this.refs = newRefs;
|
|
1206
|
-
}
|
|
1207
|
-
canUpdate(oldProps, newProps) {
|
|
1208
|
-
if (typeof this.instance.$useMemo === "function") {
|
|
1209
|
-
if (this.instance.$useMemo(newProps, oldProps)) return false;
|
|
1210
|
-
}
|
|
1211
|
-
return true;
|
|
1281
|
+
updateRefs(newRefs, this.instance, this.refEffects);
|
|
1212
1282
|
}
|
|
1213
1283
|
rerender() {
|
|
1214
1284
|
this.listener.destroy();
|
|
@@ -1270,10 +1340,24 @@ var Component = class {
|
|
|
1270
1340
|
};
|
|
1271
1341
|
/**
|
|
1272
1342
|
* 获取当前组件实例
|
|
1343
|
+
* @returns 当前组件实例
|
|
1344
|
+
* @example
|
|
1345
|
+
* ```tsx
|
|
1346
|
+
* function App() {
|
|
1347
|
+
* const instance = getCurrentInstance()
|
|
1348
|
+
* console.log(instance)
|
|
1349
|
+
* return () => <div>...</div>
|
|
1350
|
+
* }
|
|
1351
|
+
* ```
|
|
1273
1352
|
*/
|
|
1274
1353
|
function getCurrentInstance() {
|
|
1275
1354
|
return getSetupContext();
|
|
1276
1355
|
}
|
|
1356
|
+
/**
|
|
1357
|
+
* 注册组件销毁回调函数
|
|
1358
|
+
* @param fn 要注册的回调函数
|
|
1359
|
+
* @internal
|
|
1360
|
+
*/
|
|
1277
1361
|
function registryComponentDestroyCallback(fn) {
|
|
1278
1362
|
const component = getSetupContext(false);
|
|
1279
1363
|
if (component) {
|
|
@@ -1377,84 +1461,738 @@ function Portal(props) {
|
|
|
1377
1461
|
};
|
|
1378
1462
|
}
|
|
1379
1463
|
//#endregion
|
|
1380
|
-
//#region
|
|
1381
|
-
function
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
if (prevFn) prevFn();
|
|
1389
|
-
prevFn = callback(newValue, oldValue);
|
|
1390
|
-
oldValue = newValue;
|
|
1391
|
-
});
|
|
1392
|
-
pushDepContext(dep);
|
|
1393
|
-
let oldValue = trigger();
|
|
1394
|
-
popDepContext();
|
|
1395
|
-
dep.destroyCallbacks.push(() => {
|
|
1396
|
-
prevFn?.();
|
|
1397
|
-
});
|
|
1398
|
-
function unWatch() {
|
|
1399
|
-
dep.destroy();
|
|
1400
|
-
}
|
|
1401
|
-
registryComponentDestroyCallback(unWatch);
|
|
1402
|
-
return unWatch;
|
|
1464
|
+
//#region dist/index.esm.js
|
|
1465
|
+
function makeError$1(name) {
|
|
1466
|
+
return function viewflyError(message) {
|
|
1467
|
+
const error = new Error(message);
|
|
1468
|
+
error.name = `[ViewflyError: ${name}]`;
|
|
1469
|
+
error.stack = error.stack.replace(/\n.*?(?=\n)/, "");
|
|
1470
|
+
return error;
|
|
1471
|
+
};
|
|
1403
1472
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
function getInjector(start) {
|
|
1408
|
-
while (start) {
|
|
1409
|
-
const injector = injectMap.get(start);
|
|
1410
|
-
if (injector) return injector;
|
|
1411
|
-
start = start.parentComponent;
|
|
1412
|
-
}
|
|
1413
|
-
return new NullInjector();
|
|
1473
|
+
var toStr = Object.prototype.toString;
|
|
1474
|
+
function getStringType(v) {
|
|
1475
|
+
return toStr.call(v);
|
|
1414
1476
|
}
|
|
1415
|
-
function
|
|
1416
|
-
return
|
|
1417
|
-
const instance = getCurrentInstance();
|
|
1418
|
-
const injector = new ReflectiveInjector(parentInjector || getInjector(instance), providers, scope);
|
|
1419
|
-
injectMap.set(instance, injector);
|
|
1420
|
-
return () => {
|
|
1421
|
-
return props.children;
|
|
1422
|
-
};
|
|
1423
|
-
};
|
|
1477
|
+
function isArray(v) {
|
|
1478
|
+
return Array.isArray(v);
|
|
1424
1479
|
}
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
provide: params.provide,
|
|
1429
|
-
...props
|
|
1430
|
-
}]);
|
|
1431
|
-
watch(() => {
|
|
1432
|
-
return props.useClass || props.useFactory || props.useValue || props.useExisting;
|
|
1433
|
-
}, () => {
|
|
1434
|
-
Context = createContext([{
|
|
1435
|
-
provide: params.provide,
|
|
1436
|
-
...props
|
|
1437
|
-
}]);
|
|
1438
|
-
});
|
|
1439
|
-
return () => {
|
|
1440
|
-
return jsx(Context, { children: props.children });
|
|
1441
|
-
};
|
|
1442
|
-
};
|
|
1480
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1481
|
+
function hasOwn(target, key) {
|
|
1482
|
+
return hasOwnProperty.call(target, key);
|
|
1443
1483
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1484
|
+
var Dep$1 = class {
|
|
1485
|
+
destroyCallbacks = [];
|
|
1486
|
+
constructor(effect) {
|
|
1487
|
+
this.effect = effect;
|
|
1488
|
+
}
|
|
1489
|
+
destroy() {
|
|
1490
|
+
this.destroyCallbacks.forEach((callback) => callback());
|
|
1491
|
+
this.destroyCallbacks = [];
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
var deps = [];
|
|
1495
|
+
function getDepContext$1() {
|
|
1496
|
+
return deps.at(-1);
|
|
1449
1497
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1498
|
+
function pushDepContext$1(dep) {
|
|
1499
|
+
deps.push(dep);
|
|
1500
|
+
}
|
|
1501
|
+
function popDepContext$1() {
|
|
1502
|
+
deps.pop();
|
|
1503
|
+
}
|
|
1504
|
+
var subscribers = /* @__PURE__ */ new WeakMap();
|
|
1505
|
+
function getSubscriber(target) {
|
|
1506
|
+
let subscriber = subscribers.get(target);
|
|
1507
|
+
if (!subscriber) {
|
|
1508
|
+
subscriber = /* @__PURE__ */ new Map();
|
|
1509
|
+
subscribers.set(target, subscriber);
|
|
1510
|
+
}
|
|
1511
|
+
return subscriber;
|
|
1512
|
+
}
|
|
1513
|
+
var TrackOpTypes$1 = /* @__PURE__ */ function(TrackOpTypes) {
|
|
1514
|
+
TrackOpTypes["Get"] = "Get";
|
|
1515
|
+
TrackOpTypes["Has"] = "Has";
|
|
1516
|
+
TrackOpTypes["Iterate"] = "Iterate";
|
|
1517
|
+
return TrackOpTypes;
|
|
1518
|
+
}({});
|
|
1519
|
+
var TriggerOpTypes$1 = /* @__PURE__ */ function(TriggerOpTypes) {
|
|
1520
|
+
TriggerOpTypes["Set"] = "Set";
|
|
1521
|
+
TriggerOpTypes["Add"] = "Add";
|
|
1522
|
+
TriggerOpTypes["Delete"] = "Delete";
|
|
1523
|
+
TriggerOpTypes["Clear"] = "Clear";
|
|
1524
|
+
return TriggerOpTypes;
|
|
1525
|
+
}({});
|
|
1526
|
+
var unKnownKey = Symbol("unKnownKey");
|
|
1527
|
+
function track$1(target, type, key = unKnownKey) {
|
|
1528
|
+
const dep = getDepContext$1();
|
|
1529
|
+
if (dep) {
|
|
1530
|
+
const subscriber = getSubscriber(target);
|
|
1531
|
+
let record = subscriber.get(type);
|
|
1532
|
+
if (!record) {
|
|
1533
|
+
record = /* @__PURE__ */ new Map();
|
|
1534
|
+
subscriber.set(type, record);
|
|
1535
|
+
}
|
|
1536
|
+
let effects = record.get(key);
|
|
1537
|
+
if (!effects) {
|
|
1538
|
+
effects = new Set([dep]);
|
|
1539
|
+
record.set(key, effects);
|
|
1540
|
+
dep.destroyCallbacks.push(() => {
|
|
1541
|
+
effects.delete(dep);
|
|
1542
|
+
});
|
|
1543
|
+
} else if (!effects.has(dep)) {
|
|
1544
|
+
dep.destroyCallbacks.push(() => {
|
|
1545
|
+
effects.delete(dep);
|
|
1546
|
+
});
|
|
1547
|
+
effects.add(dep);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
function runEffect(key, record) {
|
|
1552
|
+
if (!record) return;
|
|
1553
|
+
const effects = record.get(key);
|
|
1554
|
+
if (effects) [...effects].forEach((i) => i.effect());
|
|
1555
|
+
}
|
|
1556
|
+
function trigger$1(target, type, key = unKnownKey) {
|
|
1557
|
+
const subscriber = getSubscriber(target);
|
|
1558
|
+
if (subscriber) switch (type) {
|
|
1559
|
+
case TriggerOpTypes$1.Set:
|
|
1560
|
+
if (isArray(target)) runEffect(unKnownKey, subscriber.get(TrackOpTypes$1.Iterate));
|
|
1561
|
+
runEffect(key, subscriber.get(TrackOpTypes$1.Get));
|
|
1562
|
+
runEffect(key, subscriber.get(TrackOpTypes$1.Has));
|
|
1563
|
+
break;
|
|
1564
|
+
case TriggerOpTypes$1.Add:
|
|
1565
|
+
case TriggerOpTypes$1.Clear:
|
|
1566
|
+
case TriggerOpTypes$1.Delete:
|
|
1567
|
+
runEffect(unKnownKey, subscriber.get(TrackOpTypes$1.Iterate));
|
|
1568
|
+
runEffect(key, subscriber.get(TrackOpTypes$1.Has));
|
|
1569
|
+
runEffect(key, subscriber.get(TrackOpTypes$1.Get));
|
|
1570
|
+
break;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
function createIterableIterator(wrapper) {
|
|
1574
|
+
return {
|
|
1575
|
+
*entries() {
|
|
1576
|
+
const target = toRaw$1(this);
|
|
1577
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1578
|
+
for (const [key, value] of target.entries()) yield [wrapper(key), wrapper(value)];
|
|
1579
|
+
},
|
|
1580
|
+
*keys() {
|
|
1581
|
+
const target = toRaw$1(this);
|
|
1582
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1583
|
+
for (const item of target.keys()) yield wrapper(item);
|
|
1584
|
+
},
|
|
1585
|
+
*values() {
|
|
1586
|
+
const target = toRaw$1(this);
|
|
1587
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1588
|
+
for (const item of target.values()) yield wrapper(item);
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
function applyPredicateMethod(self, methodName, predicate, wrapper, thisArg) {
|
|
1593
|
+
const target = toRaw$1(self);
|
|
1594
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1595
|
+
return target[methodName]((value, index, array) => {
|
|
1596
|
+
return predicate.call(target, wrapper(value), index, array);
|
|
1597
|
+
}, thisArg);
|
|
1598
|
+
}
|
|
1599
|
+
function applySearchMethod(self, methodName, args) {
|
|
1600
|
+
const target = toRaw$1(self);
|
|
1601
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1602
|
+
return target[methodName](...args.map(toRaw$1));
|
|
1603
|
+
}
|
|
1604
|
+
function createArrayHandlers(wrapper) {
|
|
1605
|
+
return {
|
|
1606
|
+
concat(...items) {
|
|
1607
|
+
const target = toRaw$1(this);
|
|
1608
|
+
trigger$1(target, TriggerOpTypes$1.Add);
|
|
1609
|
+
return target.concat(...items);
|
|
1610
|
+
},
|
|
1611
|
+
every(predicate, thisArg) {
|
|
1612
|
+
return applyPredicateMethod(this, "every", predicate, wrapper, thisArg);
|
|
1613
|
+
},
|
|
1614
|
+
filter(predicate, thisArg) {
|
|
1615
|
+
return applyPredicateMethod(this, "filter", predicate, wrapper, thisArg);
|
|
1616
|
+
},
|
|
1617
|
+
find(predicate, thisArg) {
|
|
1618
|
+
return applyPredicateMethod(this, "find", predicate, wrapper, thisArg);
|
|
1619
|
+
},
|
|
1620
|
+
findIndex(predicate, thisArg) {
|
|
1621
|
+
return applyPredicateMethod(this, "findIndex", predicate, wrapper, thisArg);
|
|
1622
|
+
},
|
|
1623
|
+
findLast(predicate, thisArg) {
|
|
1624
|
+
return applyPredicateMethod(this, "findLast", predicate, wrapper, thisArg);
|
|
1625
|
+
},
|
|
1626
|
+
findLastIndex(predicate, thisArg) {
|
|
1627
|
+
return applyPredicateMethod(this, "findLastIndex", predicate, wrapper, thisArg);
|
|
1628
|
+
},
|
|
1629
|
+
forEach(callbackfn, thisArg) {
|
|
1630
|
+
return applyPredicateMethod(this, "forEach", callbackfn, wrapper, thisArg);
|
|
1631
|
+
},
|
|
1632
|
+
includes(...args) {
|
|
1633
|
+
return applySearchMethod(this, "includes", args);
|
|
1634
|
+
},
|
|
1635
|
+
indexOf(...args) {
|
|
1636
|
+
return applySearchMethod(this, "indexOf", args);
|
|
1637
|
+
},
|
|
1638
|
+
join(separator) {
|
|
1639
|
+
const target = toRaw$1(this);
|
|
1640
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1641
|
+
return target.join(separator);
|
|
1642
|
+
},
|
|
1643
|
+
lastIndexOf(...args) {
|
|
1644
|
+
return applySearchMethod(this, "lastIndexOf", args);
|
|
1645
|
+
},
|
|
1646
|
+
map(callbackFn, thisArg) {
|
|
1647
|
+
return applyPredicateMethod(this, "map", callbackFn, wrapper, thisArg);
|
|
1648
|
+
},
|
|
1649
|
+
pop() {
|
|
1650
|
+
const target = toRaw$1(this);
|
|
1651
|
+
trigger$1(target, TriggerOpTypes$1.Delete);
|
|
1652
|
+
return target.pop();
|
|
1653
|
+
},
|
|
1654
|
+
push(...items) {
|
|
1655
|
+
const target = toRaw$1(this);
|
|
1656
|
+
trigger$1(target, TriggerOpTypes$1.Add);
|
|
1657
|
+
return target.push(...items);
|
|
1658
|
+
},
|
|
1659
|
+
reduce(callbackFn, ...args) {
|
|
1660
|
+
const target = toRaw$1(this);
|
|
1661
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1662
|
+
return target.reduce((p, c, i, a) => {
|
|
1663
|
+
if (args.length > 0) return callbackFn(p, wrapper(c), i, a);
|
|
1664
|
+
return callbackFn(wrapper(p), wrapper(c), i, a);
|
|
1665
|
+
}, ...args);
|
|
1666
|
+
},
|
|
1667
|
+
reduceRight(callbackFn, ...args) {
|
|
1668
|
+
const target = toRaw$1(this);
|
|
1669
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1670
|
+
return target.reduceRight((p, c, i, a) => {
|
|
1671
|
+
if (args.length > 0) return callbackFn(p, wrapper(c), i, a);
|
|
1672
|
+
return callbackFn(wrapper(p), wrapper(c), i, a);
|
|
1673
|
+
}, ...args);
|
|
1674
|
+
},
|
|
1675
|
+
shift() {
|
|
1676
|
+
const target = toRaw$1(this);
|
|
1677
|
+
trigger$1(target, TriggerOpTypes$1.Delete);
|
|
1678
|
+
return target.shift();
|
|
1679
|
+
},
|
|
1680
|
+
some(predicate, thisArg) {
|
|
1681
|
+
return applyPredicateMethod(this, "some", predicate, wrapper, thisArg);
|
|
1682
|
+
},
|
|
1683
|
+
splice(start, deleteCount) {
|
|
1684
|
+
const target = toRaw$1(this);
|
|
1685
|
+
trigger$1(target, TriggerOpTypes$1.Set);
|
|
1686
|
+
trigger$1(target, TriggerOpTypes$1.Add);
|
|
1687
|
+
trigger$1(target, TriggerOpTypes$1.Delete);
|
|
1688
|
+
return target.splice(start, deleteCount).map((i) => wrapper(i));
|
|
1689
|
+
},
|
|
1690
|
+
toReversed() {
|
|
1691
|
+
const target = toRaw$1(this);
|
|
1692
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1693
|
+
return target.toReversed();
|
|
1694
|
+
},
|
|
1695
|
+
toSorted(compareFn) {
|
|
1696
|
+
const target = toRaw$1(this);
|
|
1697
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1698
|
+
return target.toSorted(compareFn);
|
|
1699
|
+
},
|
|
1700
|
+
toSpliced(start, deleteCount, ...items) {
|
|
1701
|
+
const target = toRaw$1(this);
|
|
1702
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1703
|
+
return target.toSpliced(start, deleteCount, ...items);
|
|
1704
|
+
},
|
|
1705
|
+
unshift(...items) {
|
|
1706
|
+
const target = toRaw$1(this);
|
|
1707
|
+
trigger$1(target, TriggerOpTypes$1.Add);
|
|
1708
|
+
return target.unshift(...items);
|
|
1709
|
+
},
|
|
1710
|
+
[Symbol.iterator]() {
|
|
1711
|
+
return this.values();
|
|
1712
|
+
},
|
|
1713
|
+
...createIterableIterator(wrapper)
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
function createMapHandlers(wrapper) {
|
|
1717
|
+
return {
|
|
1718
|
+
get(key) {
|
|
1719
|
+
const target = toRaw$1(this);
|
|
1720
|
+
track$1(target, TrackOpTypes$1.Get, key);
|
|
1721
|
+
return wrapper(target.get(key));
|
|
1722
|
+
},
|
|
1723
|
+
set(key, value) {
|
|
1724
|
+
const target = toRaw$1(this);
|
|
1725
|
+
key = toRaw$1(key);
|
|
1726
|
+
value = toRaw$1(value);
|
|
1727
|
+
const has = target.has(key);
|
|
1728
|
+
const r = target.set(key, value);
|
|
1729
|
+
trigger$1(target, has ? TriggerOpTypes$1.Set : TriggerOpTypes$1.Add, key);
|
|
1730
|
+
return r;
|
|
1731
|
+
},
|
|
1732
|
+
has(key) {
|
|
1733
|
+
const target = toRaw$1(this);
|
|
1734
|
+
key = toRaw$1(key);
|
|
1735
|
+
track$1(target, TrackOpTypes$1.Has, key);
|
|
1736
|
+
return target.has(key);
|
|
1737
|
+
},
|
|
1738
|
+
delete(key) {
|
|
1739
|
+
const target = toRaw$1(this);
|
|
1740
|
+
key = toRaw$1(key);
|
|
1741
|
+
const r = target.delete(key);
|
|
1742
|
+
trigger$1(target, TriggerOpTypes$1.Delete, key);
|
|
1743
|
+
return r;
|
|
1744
|
+
},
|
|
1745
|
+
forEach(callbackFn, thisArg) {
|
|
1746
|
+
const target = toRaw$1(this);
|
|
1747
|
+
track$1(target, TrackOpTypes$1.Iterate, void 0);
|
|
1748
|
+
target.forEach((v, k, m) => {
|
|
1749
|
+
callbackFn.call(this, wrapper(v), wrapper(k), m);
|
|
1750
|
+
}, thisArg);
|
|
1751
|
+
},
|
|
1752
|
+
clear() {
|
|
1753
|
+
const target = toRaw$1(this);
|
|
1754
|
+
target.clear();
|
|
1755
|
+
trigger$1(target, TriggerOpTypes$1.Clear, void 0);
|
|
1756
|
+
},
|
|
1757
|
+
[Symbol.iterator]() {
|
|
1758
|
+
return this.entries();
|
|
1759
|
+
},
|
|
1760
|
+
...createIterableIterator(wrapper)
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
function createSetHandlers(wrapper) {
|
|
1764
|
+
return {
|
|
1765
|
+
add(value) {
|
|
1766
|
+
const target = toRaw$1(this);
|
|
1767
|
+
value = toRaw$1(value);
|
|
1768
|
+
if (!target.has(value)) {
|
|
1769
|
+
target.add(value);
|
|
1770
|
+
trigger$1(target, TriggerOpTypes$1.Add, void 0);
|
|
1771
|
+
}
|
|
1772
|
+
return this;
|
|
1773
|
+
},
|
|
1774
|
+
delete(value) {
|
|
1775
|
+
const target = toRaw$1(this);
|
|
1776
|
+
value = toRaw$1(value);
|
|
1777
|
+
const has = target.has(value);
|
|
1778
|
+
const b = target.delete(value);
|
|
1779
|
+
if (!has) trigger$1(target, TriggerOpTypes$1.Delete, void 0);
|
|
1780
|
+
return b;
|
|
1781
|
+
},
|
|
1782
|
+
has(key) {
|
|
1783
|
+
const target = toRaw$1(this);
|
|
1784
|
+
key = toRaw$1(key);
|
|
1785
|
+
track$1(target, TrackOpTypes$1.Has, key);
|
|
1786
|
+
return target.has(key);
|
|
1787
|
+
},
|
|
1788
|
+
forEach(callbackFn, thisArg) {
|
|
1789
|
+
const target = toRaw$1(this);
|
|
1790
|
+
track$1(target, TrackOpTypes$1.Iterate, void 0);
|
|
1791
|
+
target.forEach((v, k, m) => {
|
|
1792
|
+
callbackFn.call(this, wrapper(v), wrapper(k), m);
|
|
1793
|
+
}, thisArg);
|
|
1794
|
+
},
|
|
1795
|
+
clear() {
|
|
1796
|
+
const target = toRaw$1(this);
|
|
1797
|
+
if (target.size !== 0) {
|
|
1798
|
+
target.clear();
|
|
1799
|
+
trigger$1(target, TriggerOpTypes$1.Clear, void 0);
|
|
1800
|
+
}
|
|
1801
|
+
},
|
|
1802
|
+
[Symbol.iterator]() {
|
|
1803
|
+
return this.values();
|
|
1804
|
+
},
|
|
1805
|
+
...createIterableIterator(wrapper)
|
|
1806
|
+
};
|
|
1807
|
+
}
|
|
1808
|
+
var reactiveErrorFn = makeError$1("reactive");
|
|
1809
|
+
var rawToProxyCache$1 = /* @__PURE__ */ new WeakMap();
|
|
1810
|
+
var proxyToRawCache$1 = /* @__PURE__ */ new WeakMap();
|
|
1811
|
+
/**
|
|
1812
|
+
* 将响应式对象转换为原始对象
|
|
1813
|
+
* @param value 响应式对象
|
|
1814
|
+
* @returns 原始对象
|
|
1815
|
+
* @example
|
|
1816
|
+
* ```tsx
|
|
1817
|
+
* const obj = reactive({
|
|
1818
|
+
* name: 'John',
|
|
1819
|
+
* age: 18
|
|
1820
|
+
* })
|
|
1821
|
+
* console.log(toRaw(obj))
|
|
1822
|
+
* ```
|
|
1823
|
+
*/
|
|
1824
|
+
function toRaw$1(value) {
|
|
1825
|
+
if (proxyToRawCache$1.has(value)) return proxyToRawCache$1.get(value);
|
|
1826
|
+
return value;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* 检查对象是否是响应式对象
|
|
1830
|
+
* @param value 要检查的对象
|
|
1831
|
+
* @returns 是否是响应式对象
|
|
1832
|
+
* @example
|
|
1833
|
+
* ```tsx
|
|
1834
|
+
* const obj = reactive({
|
|
1835
|
+
* name: 'John',
|
|
1836
|
+
* age: 18
|
|
1837
|
+
* })
|
|
1838
|
+
* console.log(isReactive(obj))
|
|
1839
|
+
* ```
|
|
1840
|
+
*/
|
|
1841
|
+
function isReactive$1(value) {
|
|
1842
|
+
return proxyToRawCache$1.has(value);
|
|
1843
|
+
}
|
|
1844
|
+
var fromInternalWrite = false;
|
|
1845
|
+
var ObjectReactiveHandler$1 = class {
|
|
1846
|
+
isShallow;
|
|
1847
|
+
isReadonly;
|
|
1848
|
+
constructor(config) {
|
|
1849
|
+
this.isReadonly = config.readonly;
|
|
1850
|
+
this.isShallow = config.shallow;
|
|
1851
|
+
}
|
|
1852
|
+
set(target, p, newValue, receiver) {
|
|
1853
|
+
if (this.isReadonly && !fromInternalWrite) throw reactiveErrorFn("Object is readonly!");
|
|
1854
|
+
const rawValue = toRaw$1(newValue);
|
|
1855
|
+
const oldValue = target[p];
|
|
1856
|
+
const v = this.isShallow ? newValue : rawValue;
|
|
1857
|
+
if (oldValue === rawValue) return Reflect.set(target, p, v, receiver);
|
|
1858
|
+
const b = Reflect.set(target, p, v, receiver);
|
|
1859
|
+
fromInternalWrite = false;
|
|
1860
|
+
if (hasOwn(target, p)) trigger$1(target, TriggerOpTypes$1.Set, p);
|
|
1861
|
+
else trigger$1(target, TriggerOpTypes$1.Add, p);
|
|
1862
|
+
return b;
|
|
1863
|
+
}
|
|
1864
|
+
get(target, p, receiver) {
|
|
1865
|
+
track$1(target, TrackOpTypes$1.Get, p);
|
|
1866
|
+
const value = Reflect.get(target, p, receiver);
|
|
1867
|
+
if (this.isShallow) return value;
|
|
1868
|
+
return reactive$1(value);
|
|
1869
|
+
}
|
|
1870
|
+
deleteProperty(target, p) {
|
|
1871
|
+
const b = Reflect.deleteProperty(target, p);
|
|
1872
|
+
trigger$1(target, TriggerOpTypes$1.Delete, p);
|
|
1873
|
+
return b;
|
|
1874
|
+
}
|
|
1875
|
+
ownKeys(target) {
|
|
1876
|
+
track$1(target, TrackOpTypes$1.Iterate);
|
|
1877
|
+
return Reflect.ownKeys(target);
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
function noReactive(v) {
|
|
1881
|
+
return v;
|
|
1882
|
+
}
|
|
1883
|
+
var ArrayReactiveHandler$1 = class extends ObjectReactiveHandler$1 {
|
|
1884
|
+
interceptors = createArrayHandlers(this.isShallow ? noReactive : reactive$1);
|
|
1885
|
+
constructor(config) {
|
|
1886
|
+
super(config);
|
|
1887
|
+
}
|
|
1888
|
+
get(target, p, receiver) {
|
|
1889
|
+
if (Reflect.has(this.interceptors, p) && p in target) return this.interceptors[p];
|
|
1890
|
+
return super.get(target, p, receiver);
|
|
1891
|
+
}
|
|
1892
|
+
};
|
|
1893
|
+
var MapReactiveHandler$1 = class extends ObjectReactiveHandler$1 {
|
|
1894
|
+
interceptors = createMapHandlers(this.isShallow ? noReactive : reactive$1);
|
|
1895
|
+
constructor(config) {
|
|
1896
|
+
super(config);
|
|
1897
|
+
}
|
|
1898
|
+
get(target, p, receiver) {
|
|
1899
|
+
if (Reflect.has(this.interceptors, p) && p in target) return this.interceptors[p];
|
|
1900
|
+
if (p === "size") {
|
|
1901
|
+
track$1(target, TrackOpTypes$1.Iterate, p);
|
|
1902
|
+
return Reflect.get(target, p);
|
|
1903
|
+
}
|
|
1904
|
+
return super.get(target, p, receiver);
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
var SetReactiveHandler$1 = class extends ObjectReactiveHandler$1 {
|
|
1908
|
+
interceptors = createSetHandlers(this.isShallow ? noReactive : reactive$1);
|
|
1909
|
+
constructor(config) {
|
|
1910
|
+
super(config);
|
|
1911
|
+
}
|
|
1912
|
+
get(target, p, receiver) {
|
|
1913
|
+
if (Reflect.has(this.interceptors, p) && p in target) return this.interceptors[p];
|
|
1914
|
+
if (p === "size") {
|
|
1915
|
+
track$1(target, TrackOpTypes$1.Iterate, p);
|
|
1916
|
+
return Reflect.get(target, p);
|
|
1917
|
+
}
|
|
1918
|
+
return super.get(target, p, receiver);
|
|
1919
|
+
}
|
|
1920
|
+
};
|
|
1921
|
+
var defaultObjectReactiveHandler$1 = new ObjectReactiveHandler$1({
|
|
1922
|
+
readonly: false,
|
|
1923
|
+
shallow: false
|
|
1924
|
+
});
|
|
1925
|
+
var defaultArrayReactiveHandler$1 = new ArrayReactiveHandler$1({
|
|
1926
|
+
readonly: false,
|
|
1927
|
+
shallow: false
|
|
1928
|
+
});
|
|
1929
|
+
var defaultMapReactiveHandler$1 = new MapReactiveHandler$1({
|
|
1930
|
+
readonly: false,
|
|
1931
|
+
shallow: false
|
|
1932
|
+
});
|
|
1933
|
+
var defaultSetReactiveHandler$1 = new SetReactiveHandler$1({
|
|
1934
|
+
readonly: false,
|
|
1935
|
+
shallow: false
|
|
1936
|
+
});
|
|
1937
|
+
new ObjectReactiveHandler$1({
|
|
1938
|
+
shallow: true,
|
|
1939
|
+
readonly: true
|
|
1940
|
+
});
|
|
1941
|
+
/**
|
|
1942
|
+
* 创建一个响应式对象
|
|
1943
|
+
* @param raw 原始对象
|
|
1944
|
+
* @returns 响应式对象
|
|
1945
|
+
* @example
|
|
1946
|
+
* ```tsx
|
|
1947
|
+
* const obj = reactive({
|
|
1948
|
+
* name: 'John',
|
|
1949
|
+
* age: 18,
|
|
1950
|
+
* children: [
|
|
1951
|
+
* {
|
|
1952
|
+
* name: 'Jane',
|
|
1953
|
+
* age: 16
|
|
1954
|
+
* }
|
|
1955
|
+
* ]
|
|
1956
|
+
* })
|
|
1957
|
+
* console.log(obj.name)
|
|
1958
|
+
* console.log(obj.children[0].name)
|
|
1959
|
+
* ```
|
|
1960
|
+
*/
|
|
1961
|
+
function reactive$1(raw) {
|
|
1962
|
+
if (isReactive$1(raw)) return raw;
|
|
1963
|
+
let proxy = rawToProxyCache$1.get(raw);
|
|
1964
|
+
if (proxy) return proxy;
|
|
1965
|
+
switch (getStringType(raw)) {
|
|
1966
|
+
case "[object Object]":
|
|
1967
|
+
proxy = new Proxy(raw, defaultObjectReactiveHandler$1);
|
|
1968
|
+
break;
|
|
1969
|
+
case "[object Array]":
|
|
1970
|
+
proxy = new Proxy(raw, defaultArrayReactiveHandler$1);
|
|
1971
|
+
break;
|
|
1972
|
+
case "[object Set]":
|
|
1973
|
+
case "[object WeakSet]":
|
|
1974
|
+
proxy = new Proxy(raw, defaultSetReactiveHandler$1);
|
|
1975
|
+
break;
|
|
1976
|
+
case "[object Map]":
|
|
1977
|
+
case "[object WeakMap]":
|
|
1978
|
+
proxy = new Proxy(raw, defaultMapReactiveHandler$1);
|
|
1979
|
+
break;
|
|
1980
|
+
default: return raw;
|
|
1981
|
+
}
|
|
1982
|
+
rawToProxyCache$1.set(raw, proxy);
|
|
1983
|
+
proxyToRawCache$1.set(proxy, raw);
|
|
1984
|
+
return proxy;
|
|
1985
|
+
}
|
|
1986
|
+
makeError$1("Ref");
|
|
1987
|
+
var componentSetupStack = [];
|
|
1988
|
+
var componentErrorFn = makeError$1("component");
|
|
1989
|
+
function getSetupContext$1(need = true) {
|
|
1990
|
+
const current = componentSetupStack[componentSetupStack.length - 1];
|
|
1991
|
+
if (!current && need) throw componentErrorFn("cannot be called outside the component!");
|
|
1992
|
+
return current;
|
|
1993
|
+
}
|
|
1994
|
+
/**
|
|
1995
|
+
* 注册组件销毁回调函数
|
|
1996
|
+
* @param fn 要注册的回调函数
|
|
1997
|
+
* @internal
|
|
1998
|
+
*/
|
|
1999
|
+
function registryComponentDestroyCallback$1(fn) {
|
|
2000
|
+
const component = getSetupContext$1(false);
|
|
2001
|
+
if (component) {
|
|
2002
|
+
if (!component.unmountedCallbacks) component.unmountedCallbacks = [];
|
|
2003
|
+
component.unmountedCallbacks.push(fn);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
makeError$1("Viewfly");
|
|
2007
|
+
new ObjectReactiveHandler$1({
|
|
2008
|
+
readonly: false,
|
|
2009
|
+
shallow: true
|
|
2010
|
+
});
|
|
2011
|
+
new ArrayReactiveHandler$1({
|
|
2012
|
+
readonly: false,
|
|
2013
|
+
shallow: true
|
|
2014
|
+
});
|
|
2015
|
+
new MapReactiveHandler$1({
|
|
2016
|
+
readonly: false,
|
|
2017
|
+
shallow: true
|
|
2018
|
+
});
|
|
2019
|
+
new SetReactiveHandler$1({
|
|
2020
|
+
readonly: false,
|
|
2021
|
+
shallow: true
|
|
2022
|
+
});
|
|
2023
|
+
//#endregion
|
|
2024
|
+
//#region src/reactive/watch-effect.ts
|
|
2025
|
+
/**
|
|
2026
|
+
* 创建一个 watchEffect,立即执行 effect 函数,当依赖的值发生变化时,会再次执行 effect 函数。
|
|
2027
|
+
* watchEffect 会返回一个函数,用于停止监听
|
|
2028
|
+
* @param effect 执行的函数
|
|
2029
|
+
* @returns 一个函数,用于停止监听
|
|
2030
|
+
*/
|
|
2031
|
+
function watchEffect(effect) {
|
|
2032
|
+
const dep = new Dep$1(function() {
|
|
2033
|
+
pushDepContext$1(dep);
|
|
2034
|
+
effect();
|
|
2035
|
+
popDepContext$1();
|
|
2036
|
+
});
|
|
2037
|
+
pushDepContext$1(dep);
|
|
2038
|
+
effect();
|
|
2039
|
+
popDepContext$1();
|
|
2040
|
+
function unWatch() {
|
|
2041
|
+
dep.destroy();
|
|
2042
|
+
}
|
|
2043
|
+
registryComponentDestroyCallback$1(unWatch);
|
|
2044
|
+
return unWatch;
|
|
2045
|
+
}
|
|
2046
|
+
//#endregion
|
|
2047
|
+
//#region src/reactive/watch.ts
|
|
2048
|
+
/**
|
|
2049
|
+
* 创建一个 watch,当依赖的值发生变化时,会执行 callback 函数。
|
|
2050
|
+
* watch 会返回一个函数,用于停止监听。
|
|
2051
|
+
* @param trigger 触发函数,用于获取依赖的值
|
|
2052
|
+
* @param callback 回调函数,当依赖的值发生变化时,会执行 callback 函数
|
|
2053
|
+
* @returns 一个函数,用于停止监听
|
|
2054
|
+
*/
|
|
2055
|
+
function watch(trigger, callback) {
|
|
2056
|
+
const initValue = {};
|
|
2057
|
+
let oldValue = initValue;
|
|
2058
|
+
const unWatch = watchEffect(function() {
|
|
2059
|
+
if (oldValue === initValue) {
|
|
2060
|
+
oldValue = trigger();
|
|
2061
|
+
return;
|
|
2062
|
+
}
|
|
2063
|
+
const newValue = trigger();
|
|
2064
|
+
if (newValue !== oldValue) {
|
|
2065
|
+
callback(newValue, oldValue);
|
|
2066
|
+
oldValue = newValue;
|
|
2067
|
+
}
|
|
2068
|
+
});
|
|
2069
|
+
registryComponentDestroyCallback(unWatch);
|
|
2070
|
+
return unWatch;
|
|
2071
|
+
}
|
|
2072
|
+
//#endregion
|
|
2073
|
+
//#region src/base/context.ts
|
|
2074
|
+
var injectMap = /* @__PURE__ */ new WeakMap();
|
|
2075
|
+
function getInjector(start) {
|
|
2076
|
+
while (start) {
|
|
2077
|
+
const injector = injectMap.get(start);
|
|
2078
|
+
if (injector) return injector;
|
|
2079
|
+
start = start.parentComponent;
|
|
2080
|
+
}
|
|
2081
|
+
return new NullInjector();
|
|
2082
|
+
}
|
|
2083
|
+
/**
|
|
2084
|
+
* 创建一个上下文,用于在组件之间共享数据
|
|
2085
|
+
* @param providers 提供者,用于提供数据
|
|
2086
|
+
* @param scope 作用域,用于限制提供者的作用域
|
|
2087
|
+
* @param parentInjector 父注入器,用于自定义父注入器,默认从当前组件树中自动获取
|
|
2088
|
+
* @returns 一个上下文组件,组件的子元素都可以通过 inject 获取到提供者提供的数据
|
|
2089
|
+
* @example
|
|
2090
|
+
* ```tsx
|
|
2091
|
+
* @Injectable()
|
|
2092
|
+
* class ExampleService {}
|
|
2093
|
+
*
|
|
2094
|
+
* function Child(props) {
|
|
2095
|
+
* const exampleService = inject(ExampleService)
|
|
2096
|
+
* console.log(exampleService)
|
|
2097
|
+
* return () => {
|
|
2098
|
+
* return <div>{props.children}</div>
|
|
2099
|
+
* }
|
|
2100
|
+
* }
|
|
2101
|
+
* function App() {
|
|
2102
|
+
* const Context = createContext([
|
|
2103
|
+
* ExampleService
|
|
2104
|
+
* ])
|
|
2105
|
+
* return () => {
|
|
2106
|
+
* return <Context>
|
|
2107
|
+
* <Child>test</Child>
|
|
2108
|
+
* </Context>
|
|
2109
|
+
* }
|
|
2110
|
+
* }
|
|
2111
|
+
* ```
|
|
2112
|
+
*/
|
|
2113
|
+
function createContext(providers, scope, parentInjector) {
|
|
2114
|
+
return function context(props) {
|
|
2115
|
+
const instance = getCurrentInstance();
|
|
2116
|
+
const injector = new ReflectiveInjector(parentInjector || getInjector(instance), providers, scope);
|
|
2117
|
+
injectMap.set(instance, injector);
|
|
2118
|
+
return () => {
|
|
2119
|
+
return props.children;
|
|
2120
|
+
};
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* 创建一个上下文提供者组件,组件的子元素都可以通过 inject 获取到提供者提供的数据
|
|
2125
|
+
* @param params 提供者参数
|
|
2126
|
+
* @returns 一个上下文提供者组件,组件的子元素都可以通过 inject 获取到提供者提供的数据
|
|
2127
|
+
* @example
|
|
2128
|
+
* ```tsx
|
|
2129
|
+
* const ExampleService = createContextProvider({
|
|
2130
|
+
* provide: ExampleService
|
|
2131
|
+
* })
|
|
2132
|
+
*
|
|
2133
|
+
* function Child() {
|
|
2134
|
+
* const exampleService = inject(ExampleService)
|
|
2135
|
+
* console.log(exampleService)
|
|
2136
|
+
* return () => {
|
|
2137
|
+
* return <div>{exampleService.name}</div>
|
|
2138
|
+
* }
|
|
2139
|
+
* }
|
|
2140
|
+
*
|
|
2141
|
+
* function App() {
|
|
2142
|
+
* const value = new ExampleService()
|
|
2143
|
+
* return () => {
|
|
2144
|
+
* return <ExampleService useValue={value}>
|
|
2145
|
+
* <Child/>
|
|
2146
|
+
* </ExampleService>
|
|
2147
|
+
* }
|
|
2148
|
+
* }
|
|
2149
|
+
*/
|
|
2150
|
+
function createContextProvider(params) {
|
|
2151
|
+
return function contextProvider(props) {
|
|
2152
|
+
let Context = createContext([{
|
|
2153
|
+
provide: params.provide,
|
|
2154
|
+
...props
|
|
2155
|
+
}]);
|
|
2156
|
+
watch(() => {
|
|
2157
|
+
return props.useClass || props.useFactory || props.useValue || props.useExisting;
|
|
2158
|
+
}, () => {
|
|
2159
|
+
Context = createContext([{
|
|
2160
|
+
provide: params.provide,
|
|
2161
|
+
...props
|
|
2162
|
+
}]);
|
|
2163
|
+
});
|
|
2164
|
+
return () => {
|
|
2165
|
+
return jsx(Context, { children: props.children });
|
|
2166
|
+
};
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
/**
|
|
2170
|
+
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
2171
|
+
* @param token 注入的 token
|
|
2172
|
+
* @param notFoundValue 未找到时的值
|
|
2173
|
+
* @param flags 注入标志
|
|
2174
|
+
* @returns 注入的值
|
|
2175
|
+
* @example
|
|
2176
|
+
* ```tsx
|
|
2177
|
+
* function ChildComponent() {
|
|
2178
|
+
* const exampleService = inject(ExampleService)
|
|
2179
|
+
* console.log(exampleService)
|
|
2180
|
+
* return () => {
|
|
2181
|
+
* return <div>{exampleService.name}</div>
|
|
2182
|
+
* }
|
|
2183
|
+
* }
|
|
2184
|
+
*/
|
|
2185
|
+
function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
|
|
2186
|
+
return getInjector(getCurrentInstance()).get(token, notFoundValue, flags);
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* 给组件添加注解
|
|
2190
|
+
* @param annotation
|
|
2191
|
+
* @param componentSetup
|
|
2192
|
+
* @example
|
|
2193
|
+
* ```ts
|
|
2194
|
+
* export customScope = new Scope('scopeName')
|
|
2195
|
+
* export const App = withAnnotation({
|
|
1458
2196
|
* scope: customScope,
|
|
1459
2197
|
* providers: [
|
|
1460
2198
|
* ExampleService
|
|
@@ -1483,21 +2221,9 @@ function withAnnotation(annotation, componentSetup) {
|
|
|
1483
2221
|
//#region src/base/injection-tokens.ts
|
|
1484
2222
|
var NativeRenderer = class {};
|
|
1485
2223
|
//#endregion
|
|
1486
|
-
//#region src/base/memo.ts
|
|
1487
|
-
/**
|
|
1488
|
-
* @deprecated 即将弃用,Viewfly 默认就有 memo 的效果
|
|
1489
|
-
* @param canUseMemo
|
|
1490
|
-
* @param render
|
|
1491
|
-
*/
|
|
1492
|
-
function withMemo(canUseMemo, render) {
|
|
1493
|
-
return {
|
|
1494
|
-
$useMemo: canUseMemo,
|
|
1495
|
-
$render: render
|
|
1496
|
-
};
|
|
1497
|
-
}
|
|
1498
|
-
//#endregion
|
|
1499
2224
|
//#region src/base/renderer.ts
|
|
1500
2225
|
var listenerReg = /^on[A-Z]/;
|
|
2226
|
+
var nativeNodeRefRecord = /* @__PURE__ */ new Map();
|
|
1501
2227
|
function createRenderer(component, nativeRenderer, namespace) {
|
|
1502
2228
|
let isInit = true;
|
|
1503
2229
|
return function render(host) {
|
|
@@ -1542,21 +2268,19 @@ function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, contex
|
|
|
1542
2268
|
}
|
|
1543
2269
|
function deepUpdateByComponentDirtyTree(nativeRenderer, component, needMove) {
|
|
1544
2270
|
if (component.dirty) {
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
view.isParent = context.isParent;
|
|
1559
|
-
}
|
|
2271
|
+
const { atom, host, isParent, rootHost } = component.viewMetadata;
|
|
2272
|
+
const context = {
|
|
2273
|
+
host,
|
|
2274
|
+
isParent,
|
|
2275
|
+
rootHost
|
|
2276
|
+
};
|
|
2277
|
+
const diffAtom = atom.child;
|
|
2278
|
+
patchComponent(nativeRenderer, component, diffAtom, atom, context, needMove);
|
|
2279
|
+
const next = atom.sibling;
|
|
2280
|
+
if (next && next.jsxNode instanceof Component) {
|
|
2281
|
+
const view = next.jsxNode.viewMetadata;
|
|
2282
|
+
view.host = context.host;
|
|
2283
|
+
view.isParent = context.isParent;
|
|
1560
2284
|
}
|
|
1561
2285
|
component.rendered();
|
|
1562
2286
|
} else if (component.changed) {
|
|
@@ -1663,10 +2387,9 @@ function updateComponent(nativeRenderer, context, offset, needMove, newAtom, old
|
|
|
1663
2387
|
const newProps = newAtom.jsxNode.props;
|
|
1664
2388
|
newAtom.jsxNode = component;
|
|
1665
2389
|
needMove = needMove || newAtom.index - offset !== oldAtom.index;
|
|
1666
|
-
const canUpdate = component.canUpdate(component.props, newProps);
|
|
1667
2390
|
const propsIsChanged = hasChange(newProps, component.props);
|
|
1668
2391
|
if (propsIsChanged) component.updateProps(newProps);
|
|
1669
|
-
if (
|
|
2392
|
+
if (propsIsChanged || component.dirty) {
|
|
1670
2393
|
patchComponent(nativeRenderer, component, oldAtom.child, newAtom, context, needMove);
|
|
1671
2394
|
const next = oldAtom.sibling;
|
|
1672
2395
|
if (next && next.jsxNode instanceof Component) {
|
|
@@ -1676,7 +2399,7 @@ function updateComponent(nativeRenderer, context, offset, needMove, newAtom, old
|
|
|
1676
2399
|
}
|
|
1677
2400
|
} else {
|
|
1678
2401
|
newAtom.child = oldAtom.child;
|
|
1679
|
-
reuseComponentView(nativeRenderer, newAtom.child, context, needMove, !
|
|
2402
|
+
reuseComponentView(nativeRenderer, newAtom.child, context, needMove, !component.changedSubComponents.size);
|
|
1680
2403
|
}
|
|
1681
2404
|
component.rendered();
|
|
1682
2405
|
}
|
|
@@ -1727,8 +2450,10 @@ function cleanView(nativeRenderer, atom, needClean) {
|
|
|
1727
2450
|
needClean = false;
|
|
1728
2451
|
}
|
|
1729
2452
|
if (atom.type === ElementAtomType) {
|
|
1730
|
-
const
|
|
1731
|
-
|
|
2453
|
+
const record = nativeNodeRefRecord.get(atom);
|
|
2454
|
+
if (record) record.forEach((fn) => {
|
|
2455
|
+
if (typeof fn === "function") fn();
|
|
2456
|
+
});
|
|
1732
2457
|
}
|
|
1733
2458
|
cleanChildren(atom, nativeRenderer, needClean);
|
|
1734
2459
|
}
|
|
@@ -1852,7 +2577,9 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
|
1852
2577
|
});
|
|
1853
2578
|
context.host = nativeNode;
|
|
1854
2579
|
context.isParent = false;
|
|
1855
|
-
|
|
2580
|
+
const refEffects = /* @__PURE__ */ new Map();
|
|
2581
|
+
nativeNodeRefRecord.set(atom, refEffects);
|
|
2582
|
+
applyRefs(bindingRefs, nativeNode, refEffects);
|
|
1856
2583
|
}
|
|
1857
2584
|
function createTextNode(nativeRenderer, atom, context) {
|
|
1858
2585
|
const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.namespace);
|
|
@@ -1871,7 +2598,6 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1871
2598
|
reuseElementChildrenView(nativeRenderer, newAtom, context);
|
|
1872
2599
|
return;
|
|
1873
2600
|
}
|
|
1874
|
-
let unBindRefs;
|
|
1875
2601
|
let bindRefs;
|
|
1876
2602
|
let updatedChildren = false;
|
|
1877
2603
|
comparePropsWithCallbacks(oldVNode.props, newVNode.props, (key, oldValue) => {
|
|
@@ -1892,10 +2618,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1892
2618
|
if (typeof oldValue === "function") nativeRenderer.unListen(nativeNode, key, oldValue, isSvg);
|
|
1893
2619
|
return;
|
|
1894
2620
|
}
|
|
1895
|
-
if (key === "ref")
|
|
1896
|
-
unBindRefs = oldValue;
|
|
1897
|
-
return;
|
|
1898
|
-
}
|
|
2621
|
+
if (key === "ref") return;
|
|
1899
2622
|
nativeRenderer.removeProperty(nativeNode, key, isSvg);
|
|
1900
2623
|
}, (key, value) => {
|
|
1901
2624
|
if (key === "children") {
|
|
@@ -1953,26 +2676,17 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1953
2676
|
return;
|
|
1954
2677
|
}
|
|
1955
2678
|
if (key === "ref") {
|
|
1956
|
-
unBindRefs = oldValue;
|
|
1957
2679
|
bindRefs = newValue;
|
|
1958
2680
|
return;
|
|
1959
2681
|
}
|
|
1960
2682
|
nativeRenderer.setProperty(nativeNode, key, newValue, isSvg);
|
|
1961
2683
|
});
|
|
1962
2684
|
if (!updatedChildren) newAtom.child = oldAtom.child;
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
const refList = Array.isArray(refs) ? refs : [refs];
|
|
1969
|
-
const len = refList.length;
|
|
1970
|
-
for (let i = 0; i < len; i++) {
|
|
1971
|
-
const item = refList[i];
|
|
1972
|
-
if (item instanceof DynamicRef) if (binding) item.bind(nativeNode);
|
|
1973
|
-
else item.unBind(nativeNode);
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
2685
|
+
let refEffects = nativeNodeRefRecord.get(oldAtom);
|
|
2686
|
+
if (!refEffects) refEffects = /* @__PURE__ */ new Map();
|
|
2687
|
+
nativeNodeRefRecord.delete(oldAtom);
|
|
2688
|
+
nativeNodeRefRecord.set(newAtom, refEffects);
|
|
2689
|
+
updateRefs(bindRefs, nativeNode, refEffects);
|
|
1976
2690
|
}
|
|
1977
2691
|
//#endregion
|
|
1978
2692
|
//#region src/base/root.component.ts
|
|
@@ -2056,39 +2770,16 @@ function viewfly(config) {
|
|
|
2056
2770
|
}
|
|
2057
2771
|
//#endregion
|
|
2058
2772
|
//#region src/reactive/computed.ts
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
proxy.value = value;
|
|
2070
|
-
});
|
|
2071
|
-
canListen(value);
|
|
2072
|
-
isStop = false;
|
|
2073
|
-
});
|
|
2074
|
-
pushDepContext(dep);
|
|
2075
|
-
const value = callback();
|
|
2076
|
-
popDepContext();
|
|
2077
|
-
const proxy = new Proxy({ value }, readonlyProxyHandler);
|
|
2078
|
-
function canListen(value) {
|
|
2079
|
-
if (isContinue) {
|
|
2080
|
-
if (isContinue(value) === false) {
|
|
2081
|
-
dep.destroy();
|
|
2082
|
-
return false;
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
return true;
|
|
2086
|
-
}
|
|
2087
|
-
if (!canListen(value)) return proxy;
|
|
2088
|
-
registryComponentDestroyCallback(() => {
|
|
2089
|
-
dep.destroy();
|
|
2090
|
-
});
|
|
2091
|
-
return proxy;
|
|
2773
|
+
/**
|
|
2774
|
+
* 创建一个 computed,当依赖的值发生变化时,会重新计算值。
|
|
2775
|
+
* computed 会返回一个对象,对象的 value 属性是计算的值。
|
|
2776
|
+
* @param getter 计算函数,用于计算值
|
|
2777
|
+
* @returns 一个对象,对象的 value 属性是计算的值
|
|
2778
|
+
*/
|
|
2779
|
+
function computed(getter) {
|
|
2780
|
+
return { get value() {
|
|
2781
|
+
return getter();
|
|
2782
|
+
} };
|
|
2092
2783
|
}
|
|
2093
2784
|
//#endregion
|
|
2094
2785
|
//#region src/reactive/shallow-reactive.ts
|
|
@@ -2112,7 +2803,7 @@ function shallowReactive(raw) {
|
|
|
2112
2803
|
if (isReactive(raw)) return raw;
|
|
2113
2804
|
let proxy = rawToProxyCache.get(raw);
|
|
2114
2805
|
if (proxy) return proxy;
|
|
2115
|
-
switch (getStringType(raw)) {
|
|
2806
|
+
switch (getStringType$1(raw)) {
|
|
2116
2807
|
case "[object Object]":
|
|
2117
2808
|
proxy = new Proxy(raw, defaultShallowObjectReactiveHandler);
|
|
2118
2809
|
break;
|
|
@@ -2134,7 +2825,7 @@ function shallowReactive(raw) {
|
|
|
2134
2825
|
return proxy;
|
|
2135
2826
|
}
|
|
2136
2827
|
//#endregion
|
|
2137
|
-
//#region src/
|
|
2828
|
+
//#region src/reactive/signal.ts
|
|
2138
2829
|
/**
|
|
2139
2830
|
* 组件状态管理器
|
|
2140
2831
|
* @param state 初始状态
|
|
@@ -2159,92 +2850,19 @@ function shallowReactive(raw) {
|
|
|
2159
2850
|
* }
|
|
2160
2851
|
*/
|
|
2161
2852
|
function createSignal(state) {
|
|
2162
|
-
const
|
|
2853
|
+
const ref = shallowReactive({ value: state });
|
|
2163
2854
|
function signal() {
|
|
2164
|
-
|
|
2165
|
-
if (listener && !subscribers.has(listener)) {
|
|
2166
|
-
listener.destroyCallbacks.push(() => {
|
|
2167
|
-
subscribers.delete(listener);
|
|
2168
|
-
});
|
|
2169
|
-
subscribers.add(listener);
|
|
2170
|
-
}
|
|
2171
|
-
return state;
|
|
2855
|
+
return ref.value;
|
|
2172
2856
|
}
|
|
2173
2857
|
signal.set = function(newValue) {
|
|
2174
|
-
|
|
2175
|
-
state = newValue;
|
|
2176
|
-
Array.from(subscribers).forEach((listener) => listener.effect());
|
|
2858
|
+
ref.value = newValue;
|
|
2177
2859
|
};
|
|
2178
2860
|
return signal;
|
|
2179
2861
|
}
|
|
2180
2862
|
//#endregion
|
|
2181
|
-
//#region src/signals/derived.ts
|
|
2182
|
-
/**
|
|
2183
|
-
* 使用派生值,Viewfly 会收集回调函数内同步执行时访问的 Signal,
|
|
2184
|
-
* 并在你获取 createDerived 函数返回的 Signal 的值时,自动计算最新的值。
|
|
2185
|
-
*
|
|
2186
|
-
* @param fn
|
|
2187
|
-
* @param isContinue 可选的停止函数,在每次值更新后调用,当返回值为 false 时,将不再监听依赖的变化
|
|
2188
|
-
*/
|
|
2189
|
-
function createDerived(fn, isContinue) {
|
|
2190
|
-
let isStop = false;
|
|
2191
|
-
function canListen(value) {
|
|
2192
|
-
if (isContinue) {
|
|
2193
|
-
if (isContinue(value) === false) {
|
|
2194
|
-
listener.destroy();
|
|
2195
|
-
return false;
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2198
|
-
return true;
|
|
2199
|
-
}
|
|
2200
|
-
const listener = new Dep(() => {
|
|
2201
|
-
if (isStop) return;
|
|
2202
|
-
isStop = true;
|
|
2203
|
-
listener.destroy();
|
|
2204
|
-
pushDepContext(listener);
|
|
2205
|
-
const value = fn();
|
|
2206
|
-
popDepContext();
|
|
2207
|
-
signal.set(value);
|
|
2208
|
-
canListen(value);
|
|
2209
|
-
isStop = false;
|
|
2210
|
-
});
|
|
2211
|
-
pushDepContext(listener);
|
|
2212
|
-
const value = fn();
|
|
2213
|
-
const signal = createSignal(value);
|
|
2214
|
-
popDepContext();
|
|
2215
|
-
isStop = false;
|
|
2216
|
-
if (canListen(value)) registryComponentDestroyCallback(() => listener.destroy());
|
|
2217
|
-
return signal;
|
|
2218
|
-
}
|
|
2219
|
-
//#endregion
|
|
2220
|
-
//#region src/signals/effect.ts
|
|
2221
|
-
function createEffect(deps, callback) {
|
|
2222
|
-
let prevFn;
|
|
2223
|
-
const isArray = Array.isArray(deps);
|
|
2224
|
-
const effect = new Dep(function() {
|
|
2225
|
-
if (prevFn) prevFn();
|
|
2226
|
-
const newValue = isArray ? deps.map((fn) => fn()) : deps();
|
|
2227
|
-
prevFn = callback(newValue, oldValue);
|
|
2228
|
-
oldValue = newValue;
|
|
2229
|
-
});
|
|
2230
|
-
pushDepContext(effect);
|
|
2231
|
-
let oldValue = isArray ? deps.map((fn) => fn()) : deps();
|
|
2232
|
-
popDepContext();
|
|
2233
|
-
let isUnWatch = false;
|
|
2234
|
-
function unWatch() {
|
|
2235
|
-
if (isUnWatch) return;
|
|
2236
|
-
isUnWatch = true;
|
|
2237
|
-
if (prevFn) prevFn();
|
|
2238
|
-
effect.destroy();
|
|
2239
|
-
}
|
|
2240
|
-
registryComponentDestroyCallback(unWatch);
|
|
2241
|
-
return unWatch;
|
|
2242
|
-
}
|
|
2243
|
-
//#endregion
|
|
2244
2863
|
exports.ArrayReactiveHandler = ArrayReactiveHandler;
|
|
2245
2864
|
exports.Component = Component;
|
|
2246
2865
|
exports.Dep = Dep;
|
|
2247
|
-
exports.DynamicRef = DynamicRef;
|
|
2248
2866
|
exports.ForwardRef = ForwardRef;
|
|
2249
2867
|
exports.Fragment = Fragment;
|
|
2250
2868
|
exports.Inject = Inject;
|
|
@@ -2266,21 +2884,20 @@ exports.Scope = Scope;
|
|
|
2266
2884
|
exports.Self = Self;
|
|
2267
2885
|
exports.SetReactiveHandler = SetReactiveHandler;
|
|
2268
2886
|
exports.SkipSelf = SkipSelf;
|
|
2269
|
-
exports.StaticRef = StaticRef;
|
|
2270
2887
|
exports.THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
|
|
2271
2888
|
exports.TrackOpTypes = TrackOpTypes;
|
|
2272
2889
|
exports.TriggerOpTypes = TriggerOpTypes;
|
|
2273
2890
|
exports.Type = Type;
|
|
2274
2891
|
exports.applyMark = applyMark;
|
|
2892
|
+
exports.applyRefs = applyRefs;
|
|
2275
2893
|
exports.comparePropsWithCallbacks = comparePropsWithCallbacks;
|
|
2276
2894
|
exports.computed = computed;
|
|
2277
2895
|
exports.createContext = createContext;
|
|
2278
2896
|
exports.createContextProvider = createContextProvider;
|
|
2279
|
-
exports.createDerived = createDerived;
|
|
2280
2897
|
exports.createDynamicRef = createDynamicRef;
|
|
2281
|
-
exports.createEffect = createEffect;
|
|
2282
2898
|
exports.createRef = createRef;
|
|
2283
2899
|
exports.createRenderer = createRenderer;
|
|
2900
|
+
exports.createShallowReadonlyProxy = createShallowReadonlyProxy;
|
|
2284
2901
|
exports.createSignal = createSignal;
|
|
2285
2902
|
exports.defaultArrayReactiveHandler = defaultArrayReactiveHandler;
|
|
2286
2903
|
exports.defaultMapReactiveHandler = defaultMapReactiveHandler;
|
|
@@ -2315,8 +2932,9 @@ exports.shallowReactive = shallowReactive;
|
|
|
2315
2932
|
exports.toRaw = toRaw;
|
|
2316
2933
|
exports.track = track;
|
|
2317
2934
|
exports.trigger = trigger;
|
|
2935
|
+
exports.updateRefs = updateRefs;
|
|
2318
2936
|
exports.viewfly = viewfly;
|
|
2319
2937
|
exports.watch = watch;
|
|
2938
|
+
exports.watchEffect = watchEffect;
|
|
2320
2939
|
exports.withAnnotation = withAnnotation;
|
|
2321
2940
|
exports.withMark = withMark;
|
|
2322
|
-
exports.withMemo = withMemo;
|