annil 1.7.3 → 1.7.5-beta-3
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/CHANGELOG.md +30 -0
- package/README.md +11 -7
- package/dist/api/DefineComponent/NameOrPage/NameOrPathOption.d.ts +9 -0
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.d.ts +9 -0
- package/dist/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.d.ts +8 -0
- package/dist/api/DefineComponent/ReturnType/PageDoc.d.ts +9 -0
- package/dist/api/DefineComponent/RootComponent/RootComponentOption.d.ts +6 -0
- package/dist/api/DefineComponent/SubComponents/SubComponentsOption.d.ts +6 -0
- package/dist/api/DefineComponent/index.d.ts +5 -4
- package/dist/api/DefineComponent/index.js +8 -2
- package/dist/api/DefineComponent/index.js.map +1 -1
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/computedUpdater.d.ts +1 -1
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/computedUpdater.js +5 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js.map +1 -0
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/data-tracer.d.ts +3 -1
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/data-tracer.js +4 -1
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/data-tracer.js.map +1 -0
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/dependencesOptimize.js +5 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/dependencesOptimize.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPathsValue.d.ts +7 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPathsValue.js +30 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPathsValue.js.map +1 -0
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/getPropertiesValue.js +3 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js.map +1 -0
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/index.js +19 -7
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js.map +1 -0
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/initComputedAndGetCache.d.ts +9 -0
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/initComputedAndGetCache.js +21 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/initComputedAndGetCache.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.d.ts +7 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js +69 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/customEventsHandle.d.ts +6 -0
- package/dist/api/DefineComponent/normalizeOptions/customEventsHandle.js +23 -0
- package/dist/api/DefineComponent/normalizeOptions/customEventsHandle.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/index.d.ts +6 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/index.js +16 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/index.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/isPageCheck.d.ts +5 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/isPageCheck.js +17 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/isPageCheck.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/loadReceivedDataHandle.d.ts +7 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/loadReceivedDataHandle.js +20 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/loadReceivedDataHandle.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/onLoadReceivedDataHandle.d.ts +10 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/onLoadReceivedDataHandle.js +26 -0
- package/dist/api/DefineComponent/normalizeOptions/hijackHandle/onLoadReceivedDataHandle.js.map +1 -0
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/index.d.ts +20 -18
- package/dist/api/DefineComponent/normalizeOptions/index.js +77 -0
- package/dist/api/DefineComponent/normalizeOptions/index.js.map +1 -0
- package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/initStore/index.js +2 -0
- package/dist/api/DefineComponent/normalizeOptions/initStore/index.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/injectInfoHandler.d.ts +3 -0
- package/dist/api/DefineComponent/normalizeOptions/injectInfoHandler.js +43 -0
- package/dist/api/DefineComponent/normalizeOptions/injectInfoHandler.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.d.ts +5 -0
- package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js +23 -0
- package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/otherFieldsHandle.d.ts +6 -0
- package/dist/api/DefineComponent/normalizeOptions/otherFieldsHandle.js +24 -0
- package/dist/api/DefineComponent/normalizeOptions/otherFieldsHandle.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/rootComponentOptionHandle.d.ts +9 -0
- package/dist/api/DefineComponent/normalizeOptions/rootComponentOptionHandle.js +18 -0
- package/dist/api/DefineComponent/normalizeOptions/rootComponentOptionHandle.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/sameFuncFieldsCollect.d.ts +7 -0
- package/dist/api/DefineComponent/normalizeOptions/sameFuncFieldsCollect.js +16 -0
- package/dist/api/DefineComponent/normalizeOptions/sameFuncFieldsCollect.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/sameFuncOptionsHandle.d.ts +5 -0
- package/dist/api/DefineComponent/normalizeOptions/sameFuncOptionsHandle.js +34 -0
- package/dist/api/DefineComponent/normalizeOptions/sameFuncOptionsHandle.js.map +1 -0
- package/dist/api/DefineComponent/normalizeOptions/subComponentsOptionHandle.d.ts +3 -0
- package/dist/api/DefineComponent/normalizeOptions/subComponentsOptionHandle.js +11 -0
- package/dist/api/DefineComponent/normalizeOptions/subComponentsOptionHandle.js.map +1 -0
- package/dist/api/InstanceInject/instanceConfig.d.ts +4 -0
- package/dist/api/InstanceInject/instanceConfig.js +6 -4
- package/dist/api/InstanceInject/instanceConfig.js.map +1 -1
- package/dist/api/RootComponent/Computed/ComputedConstraint.d.ts +4 -1
- package/dist/api/RootComponent/Computed/ComputedOption.d.ts +23 -0
- package/dist/api/RootComponent/Computed/GetComputedDoc.d.ts +5 -0
- package/dist/api/RootComponent/CustomEvents/CustomEventConstraint.d.ts +3 -0
- package/dist/api/RootComponent/CustomEvents/CustomEventsOption.d.ts +29 -0
- package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +13 -0
- package/dist/api/RootComponent/Data/DataOption.d.ts +14 -0
- package/dist/api/RootComponent/Events/EventsConstraint.d.ts +4 -1
- package/dist/api/RootComponent/Events/EventsOption.d.ts +52 -0
- package/dist/api/RootComponent/Instance/CustomSetData.d.ts +6 -0
- package/dist/api/RootComponent/Instance/RootComponentInstance.d.ts +9 -0
- package/dist/api/RootComponent/IsPage/IsPageOption.d.ts +3 -0
- package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +5 -2
- package/dist/api/RootComponent/Lifetimes/LifetimesOption.d.ts +26 -0
- package/dist/api/RootComponent/Methods/MethodsOption.d.ts +3 -0
- package/dist/api/RootComponent/Observers/ObserversOption.d.ts +4 -0
- package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +11 -0
- package/dist/api/RootComponent/Properties/GetOptionalDoc.d.ts +3 -0
- package/dist/api/RootComponent/Properties/GetPropertiesDoc.d.ts +3 -0
- package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +4 -0
- package/dist/api/RootComponent/Properties/PropertiesConstraint.d.ts +18 -0
- package/dist/api/RootComponent/Properties/PropertiesOption.d.ts +10 -0
- package/dist/api/RootComponent/Properties/PropertiesValueValidator.d.ts +4 -0
- package/dist/api/RootComponent/RootComponentDoc.d.ts +19 -1
- package/dist/api/RootComponent/Store/StoreOption.d.ts +12 -0
- package/dist/api/RootComponent/Watch/WatchOption.d.ts +4 -0
- package/dist/api/RootComponent/index.d.ts +17 -19
- package/dist/api/RootComponent/index.js +1 -0
- package/dist/api/RootComponent/index.js.map +1 -1
- package/dist/api/SubComponent/SubComponentDoc.d.ts +9 -0
- package/dist/api/SubComponent/SubComputed/GetSubComputedDoc.d.ts +0 -1
- package/dist/api/SubComponent/SubData/SubDataConstraint.d.ts +4 -0
- package/dist/api/SubComponent/SubData/SubDataOption.d.ts +4 -0
- package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +3 -0
- package/dist/api/SubComponent/SubEvents/SubEventsOptions.d.ts +5 -0
- package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +4 -0
- package/dist/api/SubComponent/SubInherit/SubInheritOption.d.ts +6 -1
- package/dist/api/SubComponent/SubMethods/SubMethodsConstraint.d.ts +1 -3
- package/dist/api/SubComponent/SubMethods/SubMethodsOption.d.ts +3 -0
- package/dist/api/SubComponent/SubStore/SubStoreConstraint.d.ts +4 -0
- package/dist/api/SubComponent/SubStore/SubStoreOption.d.ts +14 -0
- package/dist/api/SubComponent/index.d.ts +10 -8
- package/dist/api/SubComponent/index.js +5 -0
- package/dist/api/SubComponent/index.js.map +1 -1
- package/dist/api/navigateTo.d.ts +5 -1
- package/dist/api/navigateTo.js +10 -1
- package/dist/api/navigateTo.js.map +1 -1
- package/dist/behaviors/BStore.d.ts +4 -0
- package/dist/behaviors/BStore.js +9 -0
- package/dist/behaviors/BStore.js.map +1 -1
- package/dist/behaviors/BbeforeCreated.d.ts +3 -0
- package/dist/behaviors/BbeforeCreated.js +8 -1
- package/dist/behaviors/BbeforeCreated.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/thirdLib/index.js +1 -2
- package/dist/thirdLib/index.js.map +1 -1
- package/dist/thirdLib/vant/Button.d.ts +14 -2
- package/dist/thirdLib/vant/NoticeBar.d.ts +2 -2
- package/dist/thirdLib/vant/Popup.d.ts +42 -2
- package/dist/thirdLib/wm/Textarea.d.ts +11 -2
- package/dist/thirdLib/wm/baseEvents.d.ts +39 -2
- package/dist/thirdLib/wm/scrollView.d.ts +4 -2
- package/dist/thirdLib/wm/scrollView.js +6 -0
- package/dist/thirdLib/wm/scrollView.js.map +1 -1
- package/dist/thirdLib/wm/swiper.d.ts +75 -5
- package/dist/thirdLib/wm/view.d.ts +20 -2
- package/dist/types/AddNullForObject.d.ts +3 -0
- package/dist/types/AddPrefix.d.ts +7 -0
- package/dist/types/{GenerateDoc.d.ts → CreateComponentType.d.ts} +3 -3
- package/dist/types/CreateComponentType.js +2 -0
- package/dist/types/CreateComponentType.js.map +1 -0
- package/dist/types/DetailedType.d.ts +15 -5
- package/dist/types/DocAssign.d.ts +3 -0
- package/dist/types/DocAssign.js +4 -0
- package/dist/types/DocAssign.js.map +1 -1
- package/dist/types/GetComponentPrefix.d.ts +3 -0
- package/dist/types/GetComponentPrefix.js +10 -0
- package/dist/types/GetComponentPrefix.js.map +1 -1
- package/dist/types/InferDetailedType.d.ts +3 -0
- package/dist/types/OfficialTypeAlias.d.ts +15 -13
- package/dist/types/OfficialTypeAlias.js +30 -0
- package/dist/types/OfficialTypeAlias.js.map +1 -1
- package/dist/types/RemoveInnerData.d.ts +3 -0
- package/dist/types/Replace.d.ts +11 -0
- package/dist/types/ReplacePrefix.d.ts +5 -0
- package/dist/types/ReplacePrefix.js +9 -0
- package/dist/types/ReplacePrefix.js.map +1 -1
- package/dist/types/RequiredKeys.d.ts +4 -0
- package/dist/types/Validators.js +7 -0
- package/dist/types/Validators.js.map +1 -1
- package/dist/utils/InnerMarker.js +1 -1
- package/dist/utils/InnerMarker.js.map +1 -1
- package/dist/utils/assertNonNullable.d.ts +2 -0
- package/dist/utils/assertNonNullable.js +7 -0
- package/dist/utils/assertNonNullable.js.map +1 -0
- package/dist/utils/deepClone.d.ts +3 -0
- package/dist/utils/deepClone.js +3 -0
- package/dist/utils/deepClone.js.map +1 -1
- package/dist/utils/isEmptyObject.d.ts +3 -0
- package/dist/utils/isEmptyObject.js +3 -0
- package/dist/utils/isEmptyObject.js.map +1 -1
- package/package.json +7 -7
- package/src/api/DefineComponent/ReturnType/ComponentDoc.ts +1 -0
- package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +2 -0
- package/src/api/DefineComponent/ReturnType/test/normalPageDoc.test.ts +3 -2
- package/src/api/DefineComponent/SubComponents/SubComponentsOption.ts +0 -5
- package/src/api/DefineComponent/SubComponents/test/normal.test.ts +2 -2
- package/src/api/DefineComponent/index.ts +21 -23
- package/src/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/computedUpdater.ts +1 -1
- package/src/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/data-tracer.ts +2 -3
- package/src/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/getPathsValue.ts +2 -1
- package/src/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/index.ts +7 -9
- package/src/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/isEqual.ts +2 -2
- package/src/api/DefineComponent/normalizeOptions/customEventsHandle.ts +34 -0
- package/src/api/DefineComponent/normalizeOptions/hijackHandle/index.ts +26 -0
- package/src/api/DefineComponent/normalizeOptions/hijackHandle/isPageCheck.ts +22 -0
- package/src/api/DefineComponent/normalizeOptions/hijackHandle/loadReceivedDataHandle.ts +25 -0
- package/src/api/DefineComponent/normalizeOptions/hijackHandle/onLoadReceivedDataHandle.ts +33 -0
- package/src/api/DefineComponent/normalizeOptions/index.ts +142 -0
- package/src/api/DefineComponent/{assignOptions → normalizeOptions}/initStore/index.ts +1 -0
- package/src/api/DefineComponent/normalizeOptions/injectInfoHandler.ts +51 -0
- package/src/api/DefineComponent/normalizeOptions/internalFieldProtection.ts +26 -0
- package/src/api/DefineComponent/normalizeOptions/otherFieldsHandle.ts +27 -0
- package/src/api/DefineComponent/normalizeOptions/rootComponentOptionHandle.ts +25 -0
- package/src/api/DefineComponent/normalizeOptions/sameFuncFieldsCollect.ts +22 -0
- package/src/api/DefineComponent/normalizeOptions/sameFuncOptionsHandle.ts +37 -0
- package/src/api/DefineComponent/normalizeOptions/subComponentsOptionHandle.ts +18 -0
- package/src/api/InstanceInject/inject.ts +2 -0
- package/src/api/InstanceInject/instanceConfig.ts +2 -4
- package/src/api/InstanceInject/test/normal.test.ts +1 -0
- package/src/api/RootComponent/Computed/ComputedConstraint.ts +1 -1
- package/src/api/RootComponent/Computed/test/GetComputedDoc.test.ts +1 -0
- package/src/api/RootComponent/Computed/test/normal.test.ts +2 -0
- package/src/api/RootComponent/CustomEvents/test/GetCustomEventDoc.test.ts +2 -2
- package/src/api/RootComponent/CustomEvents/test/GetFullEventDoc.test.ts +2 -1
- package/src/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.ts +2 -1
- package/src/api/RootComponent/CustomEvents/test/error.test.ts +2 -2
- package/src/api/RootComponent/CustomEvents/test/normal.test.ts +2 -0
- package/src/api/RootComponent/Data/test/GetDataDoc.test.ts +2 -2
- package/src/api/RootComponent/Data/test/normal.test.ts +3 -2
- package/src/api/RootComponent/Events/EventsConstraint.ts +1 -1
- package/src/api/RootComponent/Events/test/normal.test.ts +5 -2
- package/src/api/RootComponent/Instance/RootComponentInstance.ts +9 -0
- package/src/api/RootComponent/Instance/test/CustomEventsDoc.test.ts +1 -0
- package/src/api/RootComponent/Instance/test/customEvents/normal.test.ts +1 -0
- package/src/api/RootComponent/Instance/test/methods/mormal.test.ts +2 -2
- package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +2 -0
- package/src/api/RootComponent/Instance/test/setData/error.test.ts +1 -1
- package/src/api/RootComponent/Instance/test/setData/normal.test.ts +1 -1
- package/src/api/RootComponent/IsPage/test/normal.test.ts +2 -0
- package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +2 -2
- package/src/api/RootComponent/Lifetimes/test/error.test.ts +22 -8
- package/src/api/RootComponent/Lifetimes/test/normal.test.ts +8 -3
- package/src/api/RootComponent/Methods/test/error.test.ts +4 -4
- package/src/api/RootComponent/Methods/test/mormal.test.ts +2 -2
- package/src/api/RootComponent/Observers/test/normal.test.ts +8 -4
- package/src/api/RootComponent/PageLifetimes/test/error.test.ts +17 -7
- package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +12 -5
- package/src/api/RootComponent/Properties/test/normalEmpty.test.ts +6 -6
- package/src/api/RootComponent/Properties/test/normalOptional.test.ts +4 -4
- package/src/api/RootComponent/Properties/test/normalRequired.test.ts +3 -3
- package/src/api/RootComponent/Store/test/normal.test.ts +4 -4
- package/src/api/RootComponent/Watch/test/WatchComputed.test.ts +6 -4
- package/src/api/RootComponent/Watch/test/WatchData.test.ts +16 -12
- package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +58 -40
- package/src/api/RootComponent/Watch/test/WtachInject.test.ts +3 -2
- package/src/api/RootComponent/Watch/test/error.test.ts +4 -2
- package/src/api/RootComponent/index.ts +47 -48
- package/src/api/SubComponent/SubComputed/test/error.test.ts +6 -2
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +8 -7
- package/src/api/SubComponent/SubData/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubEvents/test/error.test.ts +4 -2
- package/src/api/SubComponent/SubEvents/test/normal.test.ts +4 -2
- package/src/api/SubComponent/SubInherit/SubInheritOption.ts +1 -3
- package/src/api/SubComponent/SubInherit/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubInstance/test/error.test.ts +1 -1
- package/src/api/SubComponent/SubInstance/test/normal.test.ts +10 -6
- package/src/api/SubComponent/SubMethods/SubMethodsConstraint.ts +1 -3
- package/src/api/SubComponent/SubMethods/test/error.test.ts +8 -2
- package/src/api/SubComponent/SubMethods/test/normarl.test.ts +6 -2
- package/src/api/SubComponent/SubReturnType/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubReturnType/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +21 -14
- package/src/api/SubComponent/SubWatch/test/WatchProperties.test.ts +58 -58
- package/src/api/SubComponent/SubWatch/test/WatchRootData.test.ts +43 -31
- package/src/api/SubComponent/SubWatch/test/WatchSubData.test.ts +9 -6
- package/src/api/SubComponent/SubWatch/test/WtachInject.test.ts +3 -2
- package/src/api/SubComponent/SubWatch/test/error.test.ts +5 -4
- package/src/api/SubComponent/index.ts +92 -95
- package/src/api/navigateTo.ts +1 -1
- package/src/behaviors/BStore.ts +7 -3
- package/src/behaviors/BbeforeCreated.ts +8 -3
- package/src/index.ts +2 -2
- package/src/thirdLib/vant/Button.ts +2 -2
- package/src/thirdLib/vant/NoticeBar.ts +2 -2
- package/src/thirdLib/vant/Popup.ts +2 -2
- package/src/thirdLib/wm/Textarea.ts +2 -2
- package/src/thirdLib/wm/baseEvents.ts +3 -2
- package/src/thirdLib/wm/scrollView.ts +4 -2
- package/src/thirdLib/wm/swiper.ts +10 -5
- package/src/thirdLib/wm/view.ts +4 -2
- package/src/types/{GenerateDoc.ts → CreateComponentType.ts} +3 -6
- package/src/types/DetailedType.ts +1 -1
- package/src/types/InferDetailedType.test.ts +8 -13
- package/src/types/OfficialTypeAlias.ts +31 -31
- package/src/utils/assertNonNullable.ts +11 -0
- package/src/utils/isEmptyObject.ts +1 -1
- package/tsconfig.json +12 -17
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.js.map +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.js.map +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/dependencesOptimize.js.map +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/getPathsValue.d.ts +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/getPathsValue.js +0 -19
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/getPathsValue.js.map +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/getPropertiesValue.js.map +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/index.js.map +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.js.map +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/isEqual.d.ts +0 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/isEqual.js +0 -48
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/isEqual.js.map +0 -1
- package/dist/api/DefineComponent/assignOptions/index.js +0 -203
- package/dist/api/DefineComponent/assignOptions/index.js.map +0 -1
- package/dist/api/DefineComponent/assignOptions/initStore/index.js.map +0 -1
- package/dist/types/CreateComponentDoc.d.ts +0 -10
- package/dist/types/CreateComponentDoc.js +0 -2
- package/dist/types/CreateComponentDoc.js.map +0 -1
- package/dist/types/GenerateDoc.js +0 -2
- package/dist/types/GenerateDoc.js.map +0 -1
- package/src/api/DefineComponent/assignOptions/index.ts +0 -469
- package/src/types/CreateComponentDoc.ts +0 -17
- /package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/dependencesOptimize.d.ts +0 -0
- /package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/getPropertiesValue.d.ts +0 -0
- /package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/index.d.ts +0 -0
- /package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/initStore/index.d.ts +0 -0
- /package/src/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/dependencesOptimize.ts +0 -0
- /package/src/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/getPropertiesValue.ts +0 -0
- /package/src/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/initComputedAndGetCache.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,36 @@
|
|
|
4
4
|
|
|
5
5
|
* 解决DetailedType不接收接口类型的错误 ([ae8acbf](https://github.com/missannil/annil/commit/ae8acbfc2e62f99db565c448ad9253aa549e78bb))
|
|
6
6
|
|
|
7
|
+
## [1.7.5-beta-3](https://github.com/missannil/annil/compare/v1.7.5-beta.0...v1.7.5-beta-3) (2024-08-06)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Miscellaneous Chores
|
|
11
|
+
|
|
12
|
+
* 测试 ([#185](https://github.com/missannil/annil/issues/185)) ([7da9fc8](https://github.com/missannil/annil/commit/7da9fc8d0f84167554f95a856da71310207a77fa))
|
|
13
|
+
* 测试自定义3 ([b25df03](https://github.com/missannil/annil/commit/b25df0368785499537405415072e48ea842893c7))
|
|
14
|
+
* 自定义发布 ([8fd8020](https://github.com/missannil/annil/commit/8fd802092f4d2f8d784c1530d0cd6ffdd178790a))
|
|
15
|
+
|
|
16
|
+
## [1.7.5-beta.0](https://github.com/missannil/annil/compare/v1.7.5-beta.0...v1.7.5-beta.0) (2024-08-06)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Miscellaneous Chores
|
|
20
|
+
|
|
21
|
+
* 测试自定义3 ([b25df03](https://github.com/missannil/annil/commit/b25df0368785499537405415072e48ea842893c7))
|
|
22
|
+
|
|
23
|
+
## [1.7.5-beta.0](https://github.com/missannil/annil/compare/v1.7.4...v1.7.5-beta.0) (2024-08-06)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Miscellaneous Chores
|
|
27
|
+
|
|
28
|
+
* 测试自定义发布 ([d179ebd](https://github.com/missannil/annil/commit/d179ebd36219bec5c92864fd3e2989913ade33a2))
|
|
29
|
+
|
|
30
|
+
## [1.7.4](https://github.com/missannil/annil/compare/v1.7.3...v1.7.4) (2024-06-30)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* jest.config.ts的transform项修复,update typescript version from 5.3.2 to 5.5.2 ([00e221c](https://github.com/missannil/annil/commit/00e221ca37b042f042715b26dd5d158c0671a30e))
|
|
36
|
+
|
|
7
37
|
## [1.7.3](https://github.com/missannil/annil/compare/v1.7.2...v1.7.3) (2024-05-03)
|
|
8
38
|
|
|
9
39
|
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
### 简介
|
|
25
25
|
|
|
26
|
-
annil(安奈儿)
|
|
26
|
+
annil(安奈儿)是微信小程序原生开发插件。她会让你获得新的开发体验,提高开发效率和代码质量。
|
|
27
27
|
|
|
28
28
|
### 特点
|
|
29
29
|
|
|
@@ -34,13 +34,13 @@ annil(安奈儿)是微信小程序原生开发插件。
|
|
|
34
34
|
- **复杂组件解决方案**
|
|
35
35
|
|
|
36
36
|
新的组件构建方案(根组件 + 子组件(可选)),组件逻辑与wxml标签一一对应。解决书写复杂组件时不同组件代码耦合的问题。
|
|
37
|
-
-
|
|
37
|
+
- **基于typescript设计**
|
|
38
38
|
|
|
39
|
-
annil
|
|
39
|
+
annil中的api基于原生ts设计,js开发者只需懂得定义对象类型便可。
|
|
40
40
|
|
|
41
41
|
- **组件类型概念**
|
|
42
42
|
|
|
43
|
-
新的组件构建API(DefineComponent)
|
|
43
|
+
新的组件构建API(DefineComponent)返回的类型叫组件类型,好比传统组件(UI)库为每个组件书写的使用文档,在做为子组件构建新组件(页面)时,子组件API(SubComponent)要求使用者传入组件类型,在定义选项字段时,会得到类型提示、约束和检测。这样实现了一个页面中所有子组件之间的类型耦合,无论组件嵌套多少层,无论哪层组件数据类型发生改变,所有相关组件类型都会得到感知。当您增改、重构代码时,只要无类型报错(tsc --noEmit --watch)就不会有运行时报错的心智负担。
|
|
44
44
|
|
|
45
45
|
- **高兼容性**
|
|
46
46
|
|
|
@@ -48,13 +48,13 @@ annil(安奈儿)是微信小程序原生开发插件。
|
|
|
48
48
|
|
|
49
49
|
- **类型修补**
|
|
50
50
|
|
|
51
|
-
官方类型(miniprogram-api-typings)存在更新不及时等问题,annil
|
|
51
|
+
官方类型(miniprogram-api-typings)存在更新不及时等问题,annil提供了新的类型(补全官方类型)方便开发,这些类型都采用ES模块化,不会污染全局类型。
|
|
52
52
|
|
|
53
53
|
- **适配第三方库类型**
|
|
54
54
|
|
|
55
|
-
第三方组件库一般都是以文档的形式对组件说明,插件提供了泛型[
|
|
55
|
+
第三方组件库一般都是以文档的形式对组件说明,插件提供了泛型[CreateComponentType](./src/types/CreateComponentType.ts),可根据组件文档快速书写组件类型,使第三方组件融入组件构建模型,后续会陆续添加原生(Wm)和常用第三方组件库(Vant)类型。
|
|
56
56
|
|
|
57
|
-
-
|
|
57
|
+
- **示例Demo及设计思想**
|
|
58
58
|
|
|
59
59
|
请参考[设计思想](./doc/designIdea.md)
|
|
60
60
|
|
|
@@ -135,3 +135,7 @@ annil(安奈儿)是微信小程序原生开发插件。
|
|
|
135
135
|
### 更新日志
|
|
136
136
|
|
|
137
137
|
[CHANGELOG](./CHANGELOG.md)
|
|
138
|
+
|
|
139
|
+
测试1
|
|
140
|
+
测试2
|
|
141
|
+
测试3
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { Includes } from "../../../types/includes";
|
|
3
|
+
/**
|
|
4
|
+
* 根据IsPage,生成name或path字段
|
|
5
|
+
*/
|
|
3
6
|
export type NameOrPathOption<TName extends string, TPath extends `/${string}`, IsPage extends boolean> = IsPage extends true ? {
|
|
7
|
+
/**
|
|
8
|
+
* 页面路径已'/'开头
|
|
9
|
+
*/
|
|
4
10
|
path: TPath;
|
|
5
11
|
} : {
|
|
12
|
+
/**
|
|
13
|
+
* 组件名不可为空串和含有下划线
|
|
14
|
+
*/
|
|
6
15
|
name: TName & IfExtends<TName, "", () => "⚠️组件名不可为空⚠️", IfExtends<Includes<TName, "_">, true, () => "⚠️组件名不可包含下划线 _ ⚠️", unknown>>;
|
|
7
16
|
};
|
|
@@ -5,5 +5,14 @@ type _ComponentDoc = {
|
|
|
5
5
|
};
|
|
6
6
|
type Error = "{ properties?: Record<PrefixKeys, any>; customEvents?: Record<PrefixKeys, any>;}";
|
|
7
7
|
type _Validator<O> = keyof O extends keyof _ComponentDoc ? keyof (O["properties"] & O["customEvents"]) extends PrefixKeys ? _ComponentDoc : Error : Error;
|
|
8
|
+
/**
|
|
9
|
+
* RootComponent Api 返回的类型
|
|
10
|
+
* ```ts
|
|
11
|
+
* RootComponentDoc = {
|
|
12
|
+
* properties?: Record<PrefixKeys, any>;
|
|
13
|
+
* customEvents?: Record<PrefixKeys, any>;
|
|
14
|
+
* };
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
8
17
|
export type ComponentDoc<O extends _Validator<O> = _ComponentDoc> = O;
|
|
9
18
|
export {};
|
|
@@ -2,6 +2,14 @@ import type { IsNever, IsUnion } from "hry-types/src/Any/_api";
|
|
|
2
2
|
import type { UnionTwoObject } from "hry-types/src/Object/UnionTwoObject";
|
|
3
3
|
import type { Last } from "hry-types/src/Union/Last";
|
|
4
4
|
import type { SubComponentDoc } from "../../SubComponent/SubComponentDoc";
|
|
5
|
+
/**
|
|
6
|
+
* 因为子组件文档customEvents字段有可能相同(无前缀),所以使用UnionTwoObject
|
|
7
|
+
* 由于SubComponentDoc为空时返回never而不`{}`,所以`Exclude<U, TLast>`不影响结果。
|
|
8
|
+
*/
|
|
5
9
|
type _GetCustomEventDocOfSubDoc<U extends SubComponentDoc, Result = {}, TLast = Last<U>> = IsNever<U> extends true ? Result : _GetCustomEventDocOfSubDoc<Exclude<U, TLast>, UnionTwoObject<Result, TLast>>;
|
|
10
|
+
/**
|
|
11
|
+
* 获取子组件自定义事件文档
|
|
12
|
+
* @remarks U 中 相同字段类型联合,所以使用元组推导不如Last性能好。
|
|
13
|
+
*/
|
|
6
14
|
export type GetCustomEventDocOfSubDoc<UnionSubDoc extends SubComponentDoc> = IsUnion<UnionSubDoc> extends true ? _GetCustomEventDocOfSubDoc<UnionSubDoc> : UnionSubDoc;
|
|
7
15
|
export {};
|
|
@@ -4,5 +4,14 @@ type _PageDoc = {
|
|
|
4
4
|
};
|
|
5
5
|
type Error = "{ path: `/${string}`; properties?: object;}";
|
|
6
6
|
type _Validator<O> = keyof O extends keyof _PageDoc ? _PageDoc : Error;
|
|
7
|
+
/**
|
|
8
|
+
* 页面文档类型
|
|
9
|
+
* ```ts
|
|
10
|
+
* PageDoc = {
|
|
11
|
+
* path: `/${string}`;
|
|
12
|
+
* properties?: object;
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
7
16
|
export type PageDoc<O extends _Validator<O> = _PageDoc> = O;
|
|
8
17
|
export {};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { RootComponentDoc } from "../../RootComponent/RootComponentDoc";
|
|
2
|
+
/**
|
|
3
|
+
* DefineComponent API`rootComponent`字段配置
|
|
4
|
+
*/
|
|
2
5
|
export type RootComponentOption<TRootComponent extends RootComponentDoc> = {
|
|
6
|
+
/**
|
|
7
|
+
* 根组件配置
|
|
8
|
+
*/
|
|
3
9
|
rootComponent?: TRootComponent;
|
|
4
10
|
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { SubComponentDoc } from "../../SubComponent/SubComponentDoc";
|
|
2
|
+
/**
|
|
3
|
+
* RootComponent API 的`subComponents`字段配置
|
|
4
|
+
*/
|
|
2
5
|
export type SubComponentsOption<TSubComponentTuple extends SubComponentDoc[]> = {
|
|
6
|
+
/**
|
|
7
|
+
* 子组件列表
|
|
8
|
+
*/
|
|
3
9
|
subComponents?: [...TSubComponentTuple];
|
|
4
10
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
+
import type { RootComponentTrueOptions } from "../RootComponent";
|
|
2
3
|
import type { RootComponentDoc } from "../RootComponent/RootComponentDoc";
|
|
3
4
|
import type { SubComponentDoc } from "../SubComponent/SubComponentDoc";
|
|
4
5
|
import type { NameOrPathOption } from "./NameOrPage/NameOrPathOption";
|
|
@@ -6,17 +7,17 @@ import type { CreateComponentDoc } from "./ReturnType/CreateComponentDoc";
|
|
|
6
7
|
import type { CreatePageDoc } from "./ReturnType/CreatePageDoc";
|
|
7
8
|
import type { RootComponentOption } from "./RootComponent/RootComponentOption";
|
|
8
9
|
import type { SubComponentsOption } from "./SubComponents/SubComponentsOption";
|
|
9
|
-
import type { RootComponentTrueOptions } from "../RootComponent";
|
|
10
10
|
export type Path = `/${string}`;
|
|
11
11
|
type RootOptions<TRootComponentDoc extends RootComponentDoc, TSubComponentTuple extends SubComponentDoc[], TName extends string, TPath extends Path> = NameOrPathOption<TName, TPath, TRootComponentDoc["isPage"] & {}> & RootComponentOption<TRootComponentDoc> & SubComponentsOption<TSubComponentTuple>;
|
|
12
|
-
|
|
13
|
-
<TRootComponentDoc extends RootComponentDoc = {}, TSubComponentTuple extends SubComponentDoc[] = [], TName extends string = "", TPath extends Path = "/">(options: RootOptions<TRootComponentDoc, TSubComponentTuple, TName, TPath>): IfExtends<"", TName, CreatePageDoc<TRootComponentDoc, TPath>, CreateComponentDoc<TRootComponentDoc, TName, TSubComponentTuple>>;
|
|
14
|
-
}
|
|
12
|
+
type DefineComponentConstructor = <TRootComponentDoc extends RootComponentDoc = {}, TSubComponentTuple extends SubComponentDoc[] = [], TName extends string = "", TPath extends Path = "/">(options: RootOptions<TRootComponentDoc, TSubComponentTuple, TName, TPath>) => IfExtends<"", TName, CreatePageDoc<TRootComponentDoc, TPath>, CreateComponentDoc<TRootComponentDoc, TName, TSubComponentTuple>>;
|
|
15
13
|
export type DefineComponentOption = {
|
|
16
14
|
name?: string;
|
|
17
15
|
path?: string;
|
|
18
16
|
rootComponent?: RootComponentTrueOptions;
|
|
19
17
|
subComponents?: SubComponentDoc[];
|
|
20
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* 把根组件选项和子组件选项转化为原生Component API选项并执行
|
|
21
|
+
*/
|
|
21
22
|
export declare const DefineComponent: DefineComponentConstructor;
|
|
22
23
|
export {};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeOptions } from "./normalizeOptions";
|
|
2
|
+
/**
|
|
3
|
+
* 把根组件选项和子组件选项转化为原生Component API选项并执行
|
|
4
|
+
*/
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
6
|
export const DefineComponent = function (options) {
|
|
3
|
-
Component(
|
|
7
|
+
Component(
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
normalizeOptions(options));
|
|
4
10
|
};
|
|
5
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/DefineComponent/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/DefineComponent/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAyCtD;;GAEG;AACH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,eAAe,GAA+B,UAAS,OAAO;IACzE,SAAS;IACP,8DAA8D;IAC9D,gBAAgB,CAAC,OAAgC,CAAQ,CAC1D,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -7,7 +7,9 @@ export function computedUpdater(isUpdated = false) {
|
|
|
7
7
|
const itemCache = this.data.__computedCache__[key];
|
|
8
8
|
let changed = false;
|
|
9
9
|
for (const dep of itemCache.dependences) {
|
|
10
|
+
// getPathsValue返回的是数组
|
|
10
11
|
const curVal = getPathsValue(this.data, dep.paths.join("."))[0];
|
|
12
|
+
// 检查依赖是否更新
|
|
11
13
|
if (!isEqual(curVal, dep.val)) {
|
|
12
14
|
changed = true;
|
|
13
15
|
break;
|
|
@@ -16,11 +18,14 @@ export function computedUpdater(isUpdated = false) {
|
|
|
16
18
|
if (changed) {
|
|
17
19
|
const newDependences = [];
|
|
18
20
|
const newValue = itemCache.method.call({ data: deepProxy(this.data, newDependences) });
|
|
21
|
+
// 更新值不会立即再次进入**函数,而是当前**函数运行完毕后触发**函数,
|
|
19
22
|
this.setData({
|
|
20
23
|
[key]: getProxyOriginalValue(newValue),
|
|
21
24
|
});
|
|
22
25
|
isUpdated = true;
|
|
26
|
+
// 更新依赖(优化)
|
|
23
27
|
this.data.__computedCache__[key].dependences = removeSubDependences(newDependences);
|
|
28
|
+
// 有一个计算属性更新就重新更新所有计算互相,避免后置依赖导致前置依赖错误
|
|
24
29
|
return computedUpdater.call(this, isUpdated);
|
|
25
30
|
}
|
|
26
31
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computedUpdater.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,MAAM,UAAU,eAAe,CAAiB,SAAS,GAAG,KAAK;IAC/D,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QACnD,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,KAAK,MAAM,GAAG,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;YACxC,sBAAsB;YACtB,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAEhE,WAAW;YACX,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC9B,OAAO,GAAG,IAAI,CAAC;gBAEf,MAAM;YACR,CAAC;QACH,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,cAAc,GAAyB,EAAE,CAAC;YAChD,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC;YAEvF,uCAAuC;YACvC,IAAI,CAAC,OAAO,CAAC;gBACX,CAAC,GAAG,CAAC,EAAE,qBAAqB,CAAC,QAAQ,CAAC;aACvC,CAAC,CAAC;YAEH,SAAS,GAAG,IAAI,CAAC;YAEjB,WAAW;YACX,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,WAAW,GAAG,oBAAoB,CAAC,cAAc,CAAC,CAAC;YAEpF,sCAAsC;YACtC,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { ComputedDependence } from "./computedUpdater";
|
|
2
2
|
export declare function deepProxy(data: object, dependences: ComputedDependence[], basePath?: string[]): object;
|
|
3
|
-
export declare function getProxyOriginalValue(value:
|
|
3
|
+
export declare function getProxyOriginalValue(value: {
|
|
4
|
+
__original__?: unknown;
|
|
5
|
+
}): unknown;
|
|
@@ -6,12 +6,14 @@ export function deepProxy(data, dependences, basePath = []) {
|
|
|
6
6
|
return target;
|
|
7
7
|
}
|
|
8
8
|
const val = target[prop];
|
|
9
|
-
|
|
9
|
+
// 自身没有但原型链上有的属性不收集依赖
|
|
10
|
+
if (prop in target && !Object.prototype.hasOwnProperty.call(target, prop)) {
|
|
10
11
|
return typeof val === "function" ? val.bind(target) : val;
|
|
11
12
|
}
|
|
12
13
|
removePreviousDependence(dependences, basePath);
|
|
13
14
|
const curPath = basePath.concat(prop);
|
|
14
15
|
dependences.push({ paths: curPath, val });
|
|
16
|
+
// 非对象不代理
|
|
15
17
|
if (typeof val !== "object" || val === null)
|
|
16
18
|
return val;
|
|
17
19
|
return deepProxy(val, dependences, curPath);
|
|
@@ -30,6 +32,7 @@ export function getProxyOriginalValue(value) {
|
|
|
30
32
|
return value.__original__;
|
|
31
33
|
const ret = Array.isArray(value) ? [] : {};
|
|
32
34
|
for (const key in value) {
|
|
35
|
+
// @ts-ignore 隐式索引
|
|
33
36
|
ret[key] = getProxyOriginalValue(value[key]);
|
|
34
37
|
}
|
|
35
38
|
return ret;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-tracer.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/computedWatchHandle/data-tracer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,MAAM,UAAU,SAAS,CACvB,IAAY,EACZ,WAAiC,EACjC,WAAqB,EAAE;IAEvB,MAAM,OAAO,GAAG;QACd,GAAG,CAAmB,MAAS,EAAE,IAAsB;YACrD,IAAI,IAAI,KAAK,cAAc,EAAE,CAAC;gBAC5B,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAEzB,qBAAqB;YACrB,IAAI,IAAI,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;gBAC1E,OAAO,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;YAC5D,CAAC;YACD,wBAAwB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YAEhD,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEtC,WAAW,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;YAE1C,SAAS;YACT,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;gBAAE,OAAO,GAAG,CAAC;YAExD,OAAO,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QAC9C,CAAC;QACD,GAAG,CAAC,OAAe,EAAE,IAAY;YAC/B,MAAM,KAAK,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC;IAEF,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAiC;IACrE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC,YAAY,CAAC;IAElD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,kBAAkB;QAClB,GAAG,CAAC,GAAG,CAAC,GAAG,qBAAqB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
// 去除子依赖
|
|
1
2
|
export function removeSubDependences(dependences) {
|
|
3
|
+
// 把dependences按照路径长度排序
|
|
2
4
|
dependences.sort((a, b) => a.paths.length - b.paths.length);
|
|
5
|
+
// 从最长的路径开始遍历,如果当前路径是上一个路径的子路径,则删除当前路径
|
|
3
6
|
for (let f = 0; f < dependences.length; f++) {
|
|
4
7
|
const sortPath = dependences[f].paths.toString();
|
|
8
|
+
// 从后往前遍历,删除子依赖,保留父依赖
|
|
5
9
|
for (let i = dependences.length - 1; i > f; i--) {
|
|
6
10
|
const curPath = dependences[i].paths.toString();
|
|
7
11
|
if (curPath.startsWith(sortPath)) {
|
|
@@ -11,6 +15,7 @@ export function removeSubDependences(dependences) {
|
|
|
11
15
|
}
|
|
12
16
|
return dependences;
|
|
13
17
|
}
|
|
18
|
+
// 当前依赖是上一个依赖的子依赖时,去除上一个依赖
|
|
14
19
|
export function removePreviousDependence(dependences, basePath) {
|
|
15
20
|
if (dependences.length === 0 || basePath.length === 0)
|
|
16
21
|
return dependences;
|
package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/dependencesOptimize.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencesOptimize.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/computedWatchHandle/dependencesOptimize.ts"],"names":[],"mappings":"AACA,QAAQ;AACR,MAAM,UAAU,oBAAoB,CAAC,WAAiC;IACpE,uBAAuB;IACvB,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAE5D,sCAAsC;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjD,qBAAqB;QACrB,KAAK,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAChD,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YAChD,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACjC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,0BAA0B;AAC1B,MAAM,UAAU,wBAAwB,CAAC,WAAiC,EAAE,QAAkB;IAC5F,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,WAAW,CAAC;IAE1E,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE3D,IAAI,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC5D,WAAW,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取指定paths的值
|
|
3
|
+
* @param this - 组件实例 Instance
|
|
4
|
+
* @param paths - 支持多字段(用`,`分开) 例如 'obj.xxx,a,b.**' 监控了3个字段
|
|
5
|
+
* @returns unknown[] 每项对应paths每项的值
|
|
6
|
+
*/
|
|
7
|
+
export function getPathsValue(data, paths) {
|
|
8
|
+
const valueList = [];
|
|
9
|
+
// ['obj.xxx','a','b.**'].forEach
|
|
10
|
+
paths.split(",").forEach(path => {
|
|
11
|
+
// path : 'obj.xxx' | 'a' | 'b.**'
|
|
12
|
+
if (path.includes(".**")) {
|
|
13
|
+
// "b.**" => 'b'
|
|
14
|
+
path = path.slice(0, -3);
|
|
15
|
+
}
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
const value = path.split(".").reduce((pre, path) => {
|
|
18
|
+
// pre有可能为undefined|null,比如obj是未初始化的计算属性(undefined),还有可能是properties的对象类型(默认为null)
|
|
19
|
+
try {
|
|
20
|
+
return pre[path];
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}, data);
|
|
26
|
+
valueList.push(value);
|
|
27
|
+
});
|
|
28
|
+
return valueList;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=getPathsValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPathsValue.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/computedWatchHandle/getPathsValue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,KAAa;IACvD,MAAM,SAAS,GAAc,EAAE,CAAC;IAEhC,iCAAiC;IACjC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC9B,kCAAkC;QAClC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,gBAAgB;YAChB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC;QACD,8DAA8D;QAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,IAAI,EAAE,EAAE;YACtD,iFAAiF;YACjF,IAAI,CAAC;gBACH,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,CAAC;QAET,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -27,12 +27,15 @@ export function getPropertiesValue(propertiesOpt) {
|
|
|
27
27
|
for (const key in propertiesOpt) {
|
|
28
28
|
const config = propertiesOpt[key];
|
|
29
29
|
if (IsRequiredSingle(config)) {
|
|
30
|
+
// @ts-ignore 隐式索引
|
|
30
31
|
result[key] = getRequiredSingleValue(config);
|
|
31
32
|
}
|
|
32
33
|
else if (IsRequiredUnion(config)) {
|
|
34
|
+
// @ts-ignore 隐式索引
|
|
33
35
|
result[key] = getRequiredSingleValue(config.type);
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
38
|
+
// @ts-ignore 隐式索引
|
|
36
39
|
result[key] = config.value;
|
|
37
40
|
}
|
|
38
41
|
}
|
package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPropertiesValue.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.ts"],"names":[],"mappings":"AASA,SAAS,sBAAsB,CAC7B,QAAwB;IAExB,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,MAAM;YACT,OAAO,EAAE,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,CAAC,CAAC;QACX,KAAK,KAAK;YACR,OAAO,EAAE,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,IAAI,CAAC;QACd,KAAK,OAAO;YACV,OAAO,KAAK,CAAC;QACf;YACE,MAAM,KAAK,CACT,+DAA+D,CAChE,CAAC;IACN,CAAC;AACH,CAAC;AACD,SAAS,gBAAgB,CAAC,MAAuB;IAC/C,OAAO,MAAM,YAAY,QAAQ,CAAC;AACpC,CAAC;AACD,SAAS,eAAe,CAAC,MAAuB;IAC9C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC;AACD,MAAM,UAAU,kBAAkB,CAAC,aAA+C;IAChF,IAAI,aAAa,KAAK,SAAS;QAAE,OAAO;IACxC,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7B,kBAAkB;YAClB,MAAM,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC/C,CAAC;aAAM,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;YACnC,kBAAkB;YAClB,MAAM,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,kBAAkB;YAClB,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/api/DefineComponent/{assignOptions → normalizeOptions}/computedWatchHandle/index.js
RENAMED
|
@@ -3,41 +3,53 @@ import { getPathsValue } from "./getPathsValue";
|
|
|
3
3
|
import { getPropertiesValue } from "./getPropertiesValue";
|
|
4
4
|
import { initComputedAndGetCache } from "./initComputedAndGetCache";
|
|
5
5
|
import { isEqual } from "./isEqual";
|
|
6
|
+
import { assertNonNullable } from "../../../../utils/assertNonNullable";
|
|
6
7
|
import { deepClone } from "../../../../utils/deepClone";
|
|
7
8
|
import { isEmptyObject } from "../../../../utils/isEmptyObject";
|
|
8
9
|
function initWatchOldValue(data, watchConfig) {
|
|
9
10
|
const watchOldValue = {};
|
|
10
11
|
for (const key in watchConfig) {
|
|
12
|
+
// @ts-ignore 隐式索引
|
|
11
13
|
watchOldValue[key] = deepClone(getPathsValue(data, key));
|
|
12
14
|
}
|
|
13
15
|
return watchOldValue;
|
|
14
16
|
}
|
|
15
17
|
export function computedWatchHandle(options) {
|
|
18
|
+
// 计算属性初始化和首次依赖收集
|
|
16
19
|
const computedConfig = options.computed;
|
|
17
20
|
const rawPropertiesValue = getPropertiesValue(options.properties);
|
|
18
21
|
if (computedConfig && !isEmptyObject(computedConfig)) {
|
|
19
|
-
|
|
22
|
+
// 此时store已经初始化数据到data了(__storeConfig__)
|
|
23
|
+
const __computedInitCache__ = initComputedAndGetCache(options, computedConfig, {
|
|
24
|
+
...options.data,
|
|
25
|
+
...rawPropertiesValue,
|
|
26
|
+
});
|
|
27
|
+
// 缓存放入data中
|
|
20
28
|
options.data.__computedCache__ = __computedInitCache__;
|
|
29
|
+
// 计算属性更新函数放入methods中 要做冲突判断,避免用户定义了同名methods字段
|
|
21
30
|
options.methods.__computedUpdater__ = computedUpdater;
|
|
22
31
|
}
|
|
23
32
|
const observersConfig = options.observers;
|
|
33
|
+
// 通过observers加入`**`字段来触发计算属性更新
|
|
24
34
|
const originalFunc = observersConfig["**"];
|
|
25
35
|
observersConfig["**"] = function () {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
originalFunc
|
|
36
|
+
// 任何setData都会触发计算属性更新(可能依赖数据并没变化)
|
|
37
|
+
this.__computedUpdater__?.();
|
|
38
|
+
originalFunc?.call(this);
|
|
29
39
|
};
|
|
40
|
+
// watch handle
|
|
30
41
|
const watchConfig = options.watch;
|
|
31
42
|
if (watchConfig && !isEmptyObject(watchConfig)) {
|
|
32
43
|
const data = options.data;
|
|
33
|
-
data.__watchOldValue__ = initWatchOldValue(
|
|
44
|
+
data.__watchOldValue__ = initWatchOldValue({ ...data, ...rawPropertiesValue }, watchConfig);
|
|
34
45
|
const observersConfig = options.observers;
|
|
35
46
|
for (const key in watchConfig) {
|
|
36
47
|
const watchHadle = watchConfig[key];
|
|
37
48
|
const originObserversHandle = observersConfig[key];
|
|
49
|
+
// 在监控多个数据时,参数是多个值
|
|
38
50
|
observersConfig[key] = function (...newValue) {
|
|
39
|
-
originObserversHandle
|
|
40
|
-
const watchOldValue = this.data.__watchOldValue__;
|
|
51
|
+
originObserversHandle?.call(this, ...newValue);
|
|
52
|
+
const watchOldValue = assertNonNullable(this.data.__watchOldValue__);
|
|
41
53
|
const oldValue = watchOldValue[key];
|
|
42
54
|
if (isEqual(newValue, oldValue))
|
|
43
55
|
return;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/computedWatchHandle/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAMhE,SAAS,iBAAiB,CAAC,IAAqC,EAAE,WAAmB;IACnF,MAAM,aAAa,GAAG,EAAE,CAAC;IACzB,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,kBAAkB;QAClB,aAAa,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AACD,MAAM,UAAU,mBAAmB,CAAC,OAAgC;IAClE,iBAAiB;IACjB,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;IACxC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAClE,IAAI,cAAc,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;QACrD,wCAAwC;QAExC,MAAM,qBAAqB,GAAG,uBAAuB,CAAC,OAAO,EAAE,cAAc,EAAE;YAC7E,GAAG,OAAO,CAAC,IAAI;YACf,GAAG,kBAAkB;SACtB,CAAC,CAAC;QAEH,YAAY;QACZ,OAAO,CAAC,IAAI,CAAC,iBAAiB,GAAG,qBAAqB,CAAC;QAEvD,+CAA+C;QAC/C,OAAO,CAAC,OAAO,CAAC,mBAAmB,GAAG,eAAe,CAAC;IACxD,CAAC;IACD,MAAM,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IAC1C,+BAA+B;IAC/B,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CAAqB,CAAC;IAE/D,eAAe,CAAC,IAAI,CAAC,GAAG;QACtB,kCAAkC;QAClC,IAAI,CAAC,mBAAmB,EAAE,EAAE,CAAC;QAE7B,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC;IAEF,eAAe;IACf,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC;IAElC,IAAI,WAAW,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAE1B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,kBAAkB,EAAE,EAAE,WAAW,CAAC,CAAC;QAE5F,MAAM,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;QAC1C,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;YACpC,MAAM,qBAAqB,GAAG,eAAe,CAAC,GAAG,CAAqB,CAAC;YAEvE,kBAAkB;YAClB,eAAe,CAAC,GAAG,CAAC,GAAG,UAAyB,GAAG,QAAmB;gBACpE,qBAAqB,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;gBAE/C,MAAM,aAAa,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;gBACrE,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;gBAEpC,IAAI,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC;oBAAE,OAAO;gBACxC,aAAa,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAEzC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;YAClD,CAAC,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -8,5 +8,14 @@ type ItemCache = {
|
|
|
8
8
|
};
|
|
9
9
|
type ComputedId = string;
|
|
10
10
|
export type ComputedCache = Record<ComputedId, ItemCache>;
|
|
11
|
+
/**
|
|
12
|
+
* 把计算属性初始值加入到options.data中并返回缓存(递归函数)
|
|
13
|
+
* @param options - 配置选项
|
|
14
|
+
* @param computedConfig - 计算字段配置
|
|
15
|
+
* @param initAllData - 初始化时全部的data包含(properties,data,和已经初始化后的computed字段)
|
|
16
|
+
* @param uninitedkeys - 未初始化的key (默认为所有computedConfig的key)
|
|
17
|
+
* @param computedCache - 返回的所有计算字段缓存(默认为空对象)
|
|
18
|
+
* @returns `computedCache` 计算字段缓存
|
|
19
|
+
*/
|
|
11
20
|
export declare function initComputedAndGetCache(options: FinalOptionsOfComponent, computedConfig: Record<string, Func>, initAllData: Record<string, unknown>, uninitedkeys?: string[], computedCache?: ComputedCache): ComputedCache;
|
|
12
21
|
export {};
|
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
2
2
|
import { removeSubDependences } from "./dependencesOptimize";
|
|
3
|
+
/**
|
|
4
|
+
* 如果依赖列表某项的首个字段值为undefined并且字段为其他计算属性字段(即被依赖的计算字段写在了依赖他的计算字段后面) 返回false, 否则返回true表示依赖有效。
|
|
5
|
+
*/
|
|
3
6
|
function isValidDependences(dependences, computedKeys) {
|
|
4
7
|
for (const { paths: path, val } of dependences) {
|
|
5
8
|
if ((val === undefined) && computedKeys.includes(path[0])) {
|
|
6
9
|
return false;
|
|
7
10
|
}
|
|
8
11
|
}
|
|
12
|
+
// 依赖有效
|
|
9
13
|
return true;
|
|
10
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* 把计算属性初始值加入到options.data中并返回缓存(递归函数)
|
|
17
|
+
* @param options - 配置选项
|
|
18
|
+
* @param computedConfig - 计算字段配置
|
|
19
|
+
* @param initAllData - 初始化时全部的data包含(properties,data,和已经初始化后的computed字段)
|
|
20
|
+
* @param uninitedkeys - 未初始化的key (默认为所有computedConfig的key)
|
|
21
|
+
* @param computedCache - 返回的所有计算字段缓存(默认为空对象)
|
|
22
|
+
* @returns `computedCache` 计算字段缓存
|
|
23
|
+
*/
|
|
11
24
|
export function initComputedAndGetCache(options, computedConfig, initAllData, uninitedkeys = Object.keys(computedConfig), computedCache = {}) {
|
|
12
25
|
for (const key of uninitedkeys) {
|
|
13
26
|
const computedFunc = computedConfig[key];
|
|
14
27
|
const dependences = [];
|
|
28
|
+
// 通过代理data获取计算字段的初始值和依赖
|
|
15
29
|
let initValue = computedFunc.call({ data: deepProxy(initAllData, dependences) });
|
|
30
|
+
// 去除当前已初始的计算属性key
|
|
16
31
|
uninitedkeys = uninitedkeys.filter(ele => ele !== key);
|
|
32
|
+
// 验证依赖是否有效
|
|
17
33
|
if (isValidDependences(dependences, uninitedkeys)) {
|
|
18
34
|
initValue = getProxyOriginalValue(initValue);
|
|
35
|
+
// 把计算属性初始值加入到options.data中
|
|
19
36
|
options.data[key] = initValue;
|
|
37
|
+
// 把计算属性初始值加入到initAllData中,后续其他计算属性依赖时会可能会用到
|
|
20
38
|
initAllData[key] = initValue;
|
|
21
39
|
computedCache[key] = {
|
|
22
40
|
dependences: removeSubDependences(dependences),
|
|
@@ -25,12 +43,15 @@ export function initComputedAndGetCache(options, computedConfig, initAllData, un
|
|
|
25
43
|
};
|
|
26
44
|
}
|
|
27
45
|
else {
|
|
46
|
+
// 把当前依赖不正确的key放到后面去
|
|
28
47
|
uninitedkeys.push(key);
|
|
29
48
|
}
|
|
30
49
|
}
|
|
50
|
+
// 看uninitedkey是否未空,空表示所有依赖收集完毕直接返回
|
|
31
51
|
if (uninitedkeys.length === 0) {
|
|
32
52
|
return computedCache;
|
|
33
53
|
}
|
|
54
|
+
// uninitedkey不为空,递归
|
|
34
55
|
return initComputedAndGetCache(options, computedConfig, initAllData, uninitedkeys, computedCache);
|
|
35
56
|
}
|
|
36
57
|
//# sourceMappingURL=initComputedAndGetCache.js.map
|
package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/initComputedAndGetCache.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initComputedAndGetCache.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/computedWatchHandle/initComputedAndGetCache.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAY7D;;GAEG;AACH,SAAS,kBAAkB,CAAC,WAAiC,EAAE,YAAsB;IACnF,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,WAAW,EAAE,CAAC;QAC/C,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO;IACP,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAgC,EAChC,cAAoC,EACpC,WAAoC,EACpC,eAAyB,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EACpD,gBAA+B,EAAE;IAEjC,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QACzC,MAAM,WAAW,GAAyB,EAAE,CAAC;QAC7C,wBAAwB;QACxB,IAAI,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;QAEjF,kBAAkB;QAClB,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QAEvD,WAAW;QACX,IAAI,kBAAkB,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE,CAAC;YAClD,SAAS,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;YAE7C,2BAA2B;YAC3B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;YAE9B,4CAA4C;YAC5C,WAAW,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;YAE7B,aAAa,CAAC,GAAG,CAAC,GAAG;gBACnB,WAAW,EAAE,oBAAoB,CAAC,WAAW,CAAC;gBAC9C,MAAM,EAAE,YAAY;gBACpB,KAAK,EAAE,SAAS;aACjB,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,oBAAoB;YACpB,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IACD,mCAAmC;IACnC,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,oBAAoB;IACpB,OAAO,uBAAuB,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
function isSameType(a, b) {
|
|
2
|
+
return Object.prototype.toString.call(a) === Object.prototype.toString.call(b);
|
|
3
|
+
}
|
|
4
|
+
// 定义一个辅助函数,用于判断两个对象的属性数量是否相同
|
|
5
|
+
function isSameSize(a, b) {
|
|
6
|
+
return Object.keys(a).length === Object.keys(b).length;
|
|
7
|
+
}
|
|
8
|
+
// 定义一个辅助函数,用于判断两个函数的代码是否相同
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
10
|
+
function isSameCode(a, b) {
|
|
11
|
+
// 去除空格比较函数字符串
|
|
12
|
+
return a.toString().split(" ").join("") === b.toString().split(" ").join("");
|
|
13
|
+
}
|
|
14
|
+
// 定义一个辅助函数,用于判断两个日期的时间戳是否相同
|
|
15
|
+
function isSameTime(a, b) {
|
|
16
|
+
return a.getTime() === b.getTime();
|
|
17
|
+
}
|
|
18
|
+
// 定义一个辅助函数,用于判断两个正则表达式的模式和标志是否相同
|
|
19
|
+
function isSamePattern(a, b) {
|
|
20
|
+
return a.source === b.source && a.flags === b.flags;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 深度判断两个值是否相等,有一个值为非对象类型即使用Object.is判断。
|
|
24
|
+
* 不支持原型上的属性
|
|
25
|
+
* 两个函数使用toString()比较
|
|
26
|
+
* 支持Date,RegExp
|
|
27
|
+
*/
|
|
28
|
+
export function isEqual(a, b) {
|
|
29
|
+
// 如果两个值是原始类型或null,直接用Object.is比较
|
|
30
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") {
|
|
31
|
+
if (typeof a !== "function" || typeof b !== "function") {
|
|
32
|
+
return Object.is(a, b);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// 如果两个值是对象类型,先判断它们的类型、构造函数和属性数量是否相同
|
|
36
|
+
if (!isSameType(a, b) || a.constructor !== b.constructor || !isSameSize(a, b)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
// 如果两个值是函数类型,再判断它们的代码是否相同
|
|
40
|
+
if (typeof a === "function") {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
42
|
+
return isSameCode(a, b);
|
|
43
|
+
}
|
|
44
|
+
// 如果两个值是日期类型,再判断它们的时间戳是否相同
|
|
45
|
+
if (a instanceof Date) {
|
|
46
|
+
return isSameTime(a, b);
|
|
47
|
+
}
|
|
48
|
+
// // 如果两个值是正则表达式类型,再判断它们的模式和标志是否相同
|
|
49
|
+
if (a instanceof RegExp) {
|
|
50
|
+
return isSamePattern(a, b);
|
|
51
|
+
}
|
|
52
|
+
// 对于其他对象类型,递归地比较它们的每个属性和值是否深度相等
|
|
53
|
+
const keysA = Object.keys(a);
|
|
54
|
+
const keysB = Object.keys(b);
|
|
55
|
+
for (const key of keysA) {
|
|
56
|
+
if (keysB.includes(key)) {
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
if (!isEqual(a[key], b[key])) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// 如果以上的条件都满足,说明两个值是深度相等的
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=isEqual.js.map
|