vivth 1.4.10 → 1.5.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/README.md +6060 -2037
- package/README.src.md +22 -14
- package/bun.lock +154 -194
- package/dev/auto/.src.ignore +25 -0
- package/dev/auto-doc.mjs +137 -0
- package/generated/types/generated/vivth/exports/all.d.mts +145 -0
- package/generated/types/generated/vivth/exports/neutral.d.mts +105 -0
- package/generated/types/generated/vivth/exports/node.d.mts +40 -0
- package/generated/types/src/bundler/CompileAS.d.mts +30 -0
- package/generated/types/src/bundler/CompileJS.d.mts +109 -0
- package/{types → generated/types}/src/bundler/CreateESPlugin.d.mts +1 -1
- package/{types → generated/types}/src/bundler/EsBundler.d.mts +9 -7
- package/generated/types/src/bundler/FSAnalyzer.d.mts +58 -0
- package/generated/types/src/bundler/FSasar.bundled.d.mts +28 -0
- package/generated/types/src/bundler/FSasar.d.mts +51 -0
- package/generated/types/src/bundler/FileSelfMapper.d.mts +137 -0
- package/generated/types/src/bundler/JSDirMapper.d.mts +128 -0
- package/generated/types/src/bundler/RunWatchThenCompileJSOnSafeExit.d.mts +63 -0
- package/generated/types/src/bundler/adds/BrowserExternals.d.mts +21 -0
- package/generated/types/src/bundler/adds/CreateTransform.d.mts +26 -0
- package/generated/types/src/bundler/adds/LastEditedUnix.d.mts +5 -0
- package/generated/types/src/bundler/adds/NodeModuleList.d.mts +15 -0
- package/generated/types/src/bundler/adds/PathFSBundles.bundled.d.mts +25 -0
- package/generated/types/src/bundler/adds/PathFSBundles.d.mts +48 -0
- package/generated/types/src/bundler/adds/PathFSDir.bundled.d.mts +30 -0
- package/generated/types/src/bundler/adds/PathFSDir.d.mts +48 -0
- package/generated/types/src/bundler/adds/PathFSFile.bundled.d.mts +25 -0
- package/generated/types/src/bundler/adds/PathFSFile.d.mts +40 -0
- package/{types → generated/types}/src/bundler/adds/ToBundledJSPlugin.d.mts +6 -6
- package/generated/types/src/bundler/adds/autoExternalize.d.mts +2 -0
- package/generated/types/src/bundler/adds/emptyBufferValue.d.mts +1 -0
- package/generated/types/src/bundler/adds/isModuleTheBundledVersion.d.mts +1 -0
- package/generated/types/src/bundler/adds/onEndEsBuildErrorLogger.d.mts +1 -0
- package/generated/types/src/bundler/adds/resolveJSDependencyPath.d.mts +1 -0
- package/generated/types/src/class/AwaitSignal.d.mts +48 -0
- package/generated/types/src/class/Console.d.mts +82 -0
- package/generated/types/src/class/DataLog.d.mts +25 -0
- package/generated/types/src/class/Derived.d.mts +74 -0
- package/generated/types/src/class/Effect.d.mts +213 -0
- package/{types → generated/types}/src/class/EnvSignal.d.mts +6 -2
- package/generated/types/src/class/EsWatcher.d.mts +36 -0
- package/{types → generated/types}/src/class/EventSignal.d.mts +39 -39
- package/generated/types/src/class/FSDirArchWatcher.d.mts +110 -0
- package/{types → generated/types}/src/class/FileSafe.d.mts +32 -16
- package/generated/types/src/class/ForEach.d.mts +57 -0
- package/generated/types/src/class/ForSignal.d.mts +63 -0
- package/generated/types/src/class/GetterSetter.d.mts +38 -0
- package/generated/types/src/class/JSONFileHandler.d.mts +50 -0
- package/{types → generated/types}/src/class/ListSignal.d.mts +49 -15
- package/{types → generated/types}/src/class/LitExp.d.mts +18 -18
- package/generated/types/src/class/ObjectSignal.d.mts +267 -0
- package/generated/types/src/class/Paths.d.mts +95 -0
- package/generated/types/src/class/Prettivy.d.mts +26 -0
- package/{types → generated/types}/src/class/QChannel.d.mts +24 -16
- package/generated/types/src/class/SafeExit.d.mts +69 -0
- package/{types → generated/types}/src/class/Setup.d.mts +29 -16
- package/{types → generated/types}/src/class/Signal.d.mts +29 -15
- package/generated/types/src/class/SignalCollection.d.mts +96 -0
- package/{types → generated/types}/src/class/WalkThrough.d.mts +4 -19
- package/generated/types/src/class/WorkerMainThread.bundled.d.mts +83 -0
- package/{types → generated/types}/src/class/WorkerMainThread.d.mts +33 -39
- package/{types → generated/types}/src/class/WorkerThread.d.mts +11 -5
- package/{types → generated/types}/src/common/Base64URL.d.mts +2 -1
- package/generated/types/src/common/Base64URLFromFile.d.mts +20 -0
- package/generated/types/src/common/BundledV.bundled.d.mts +3 -0
- package/generated/types/src/common/BundledV.d.mts +36 -0
- package/{types → generated/types}/src/common/CreateStringID.d.mts +5 -4
- package/generated/types/src/common/EnvMode.d.mts +79 -0
- package/generated/types/src/common/FactoryKey.d.mts +9 -0
- package/generated/types/src/common/Preferrence.d.mts +25 -0
- package/{types → generated/types}/src/common/Trace.d.mts +1 -1
- package/{types → generated/types}/src/common/TracePath.d.mts +1 -1
- package/generated/types/src/common/VivthUnBundledCodeBlock.d.mts +6 -0
- package/generated/types/src/doc/JSautoDOC.d.mts +172 -0
- package/generated/types/src/doc/cleanPreserveTypedef.d.mts +1 -0
- package/{types/src/doc/parsedFile.d.mts → generated/types/src/doc/parsedFileForDOC.d.mts} +56 -27
- package/generated/types/src/function/ClearRequireCache.d.mts +1 -0
- package/{types → generated/types}/src/function/CreateImmutable.d.mts +5 -4
- package/{types → generated/types}/src/function/EventCheck.d.mts +3 -1
- package/{types → generated/types}/src/function/EventObject.d.mts +2 -6
- package/generated/types/src/function/ForInAsync.d.mts +36 -0
- package/generated/types/src/function/ForInSync.d.mts +36 -0
- package/generated/types/src/function/ForOfAsync.d.mts +25 -0
- package/generated/types/src/function/ForOfSync.d.mts +36 -0
- package/generated/types/src/function/GetBufferFromRelativePath.d.mts +15 -0
- package/generated/types/src/function/GetFilesFromDir.d.mts +14 -0
- package/generated/types/src/function/GetMaxFilenameLength.d.mts +9 -0
- package/generated/types/src/function/GetModuleEsbuildPlatform.d.mts +13 -0
- package/{types → generated/types}/src/function/GetNamedImportAlias.d.mts +1 -1
- package/generated/types/src/function/GetRuntime.d.mts +2 -0
- package/generated/types/src/function/InstantiateAssemblyScript.d.mts +15 -0
- package/{types → generated/types}/src/function/IsAsync.d.mts +1 -1
- package/generated/types/src/function/IsInstanceOf.d.mts +25 -0
- package/generated/types/src/function/IsSameFile.d.mts +16 -0
- package/generated/types/src/function/IsStringLooksLikeAPath.d.mts +16 -0
- package/generated/types/src/function/IsTypeOf.d.mts +25 -0
- package/{types → generated/types}/src/function/LazyFactory.d.mts +9 -10
- package/generated/types/src/function/MonkeyPatch.d.mts +33 -0
- package/generated/types/src/function/NewAnimationTimeline.d.mts +24 -0
- package/generated/types/src/function/NewChainable.d.mts +35 -0
- package/generated/types/src/function/NewDynamicsExport.d.mts +49 -0
- package/generated/types/src/function/NewObjectWrapper.d.mts +10 -0
- package/generated/types/src/function/ObjectRegistrar.d.mts +17 -0
- package/generated/types/src/function/ParseSQLFile.d.mts +25 -0
- package/generated/types/src/function/PipeAsync.d.mts +19 -0
- package/generated/types/src/function/PipeSync.d.mts +17 -0
- package/generated/types/src/function/SafeImport.d.mts +21 -0
- package/generated/types/src/function/TemplateLiteral.d.mts +23 -0
- package/{types → generated/types}/src/function/Timeout.d.mts +1 -1
- package/{types → generated/types}/src/function/Tries.d.mts +4 -4
- package/{types → generated/types}/src/function/TryAsync.d.mts +2 -2
- package/{types → generated/types}/src/function/TryNew.d.mts +1 -1
- package/generated/types/src/function/TsToMjs.d.mts +27 -0
- package/generated/types/src/function/UniqueFSTempName.d.mts +9 -0
- package/generated/types/src/function/errorToMessage.d.mts +5 -0
- package/generated/types/src/neinth/VivthyNeinth.d.mts +202 -0
- package/generated/types/src/typehints/ArrayToKeys.d.mts +23 -0
- package/generated/types/src/typehints/AssemblyScriptExportsType.d.mts +4 -0
- package/generated/types/src/typehints/AssemblyScriptLoaderInstantiate.d.mts +4 -0
- package/generated/types/src/typehints/AutoDocASOptions.d.mts +15 -0
- package/generated/types/src/typehints/ChainableType.d.mts +3 -0
- package/generated/types/src/typehints/ComponentDecorator_Constructor.d.mts +3 -0
- package/generated/types/src/typehints/ConsoleAdditionalSettingType.d.mts +3 -0
- package/generated/types/src/typehints/Decorator.d.mts +11 -0
- package/generated/types/src/typehints/DecoratorMonkeyPatch.d.mts +15 -0
- package/{types/src/types → generated/types/src/typehints}/DevTestCB.d.mts +2 -2
- package/generated/types/src/typehints/EnvModeType.d.mts +4 -0
- package/generated/types/src/typehints/ListArg.d.mts +4 -0
- package/generated/types/src/typehints/MonkeyPatchedType.d.mts +1 -0
- package/generated/types/src/typehints/ParametersFollowingN.d.mts +13 -0
- package/generated/types/src/typehints/PrefixedKeysOf.d.mts +1 -0
- package/generated/types/src/typehints/Runtime.d.mts +4 -0
- package/generated/types/src/typehints/SafeImportReturnType.d.mts +1 -0
- package/generated/types/src/typehints/StylePropRefType.d.mts +2 -0
- package/generated/types/src/typehints/TemplateLiteralValueHandler.d.mts +10 -0
- package/generated/types/src/typehints/VLifecycleCallbacks.d.mts +6 -0
- package/generated/types/src/typehints/VivthCleanup.d.mts +12 -0
- package/generated/types/src/web/BrowserDirMapper.d.mts +70 -0
- package/generated/types/src/web/EnsureValidTag.d.mts +7 -0
- package/generated/types/src/web/ViteAddDynamics.d.mts +28 -0
- package/generated/types/src/web/ViteGetAllHTMLFile.d.mts +9 -0
- package/generated/types/src/web/WC_extendsA.d.mts +135 -0
- package/generated/types/src/web/WC_extendsB.d.mts +135 -0
- package/generated/types/src/web/bindings/WC_StyleProp_bind.d.mts +42 -0
- package/generated/types/src/web/bindings/WC_createElement_bind.d.mts +51 -0
- package/generated/types/src/web/bindings/WC_createNamedSlot.d.mts +26 -0
- package/generated/types/src/web/bindings/WC_litRender_bind.d.mts +20 -0
- package/generated/types/src/web/bindings/WC_litStyleMap.d.mts +7 -0
- package/generated/types/src/web/common/CSS.d.mts +23 -0
- package/generated/types/src/web/common/E.d.mts +41 -0
- package/generated/types/src/web/common/NewStyleSheetAsync.d.mts +15 -0
- package/generated/types/src/web/common/NewStyleSheetSync.d.mts +15 -0
- package/generated/types/src/web/common/WC_TagName_type.d.mts +15 -0
- package/generated/types/src/web/signals/IsInViewPortSignal.d.mts +52 -0
- package/generated/types/src/web/signals/ObserverSignal.d.mts +32 -0
- package/generated/types/src/web/signals/WC_litRef.d.mts +26 -0
- package/generated/types/src/web/signals/WC_loopedSiblingsRef.d.mts +44 -0
- package/generated/vivth/exports/all.mjs +233 -0
- package/generated/vivth/exports/neutral.mjs +193 -0
- package/generated/vivth/exports/node.mjs +46 -0
- package/package.json +50 -14
- package/src/bundler/CompileAS.mjs +36 -0
- package/src/bundler/CompileJS.mjs +98 -171
- package/src/bundler/CreateESPlugin.mjs +1 -1
- package/src/bundler/EsBundler.mjs +38 -13
- package/src/bundler/FSAnalyzer.mjs +253 -0
- package/src/bundler/FSasar.bundled.mjs +128 -0
- package/src/bundler/FSasar.mjs +96 -0
- package/src/bundler/FileSelfMapper.mjs +491 -0
- package/src/bundler/JSDirMapper.mjs +528 -0
- package/src/bundler/RunWatchThenCompileJSOnSafeExit.mjs +129 -0
- package/src/bundler/adds/BrowserExternals.mjs +37 -0
- package/src/bundler/adds/CreateTransform.mjs +36 -0
- package/src/bundler/adds/LastEditedUnix.mjs +12 -0
- package/src/bundler/adds/NodeModuleList.mjs +33 -0
- package/src/bundler/adds/PathFSBundles.bundled.mjs +41 -0
- package/src/bundler/adds/PathFSBundles.mjs +91 -0
- package/src/bundler/adds/PathFSDir.bundled.mjs +53 -0
- package/src/bundler/adds/PathFSDir.mjs +100 -0
- package/src/bundler/adds/PathFSFile.bundled.mjs +40 -0
- package/src/bundler/adds/PathFSFile.mjs +85 -0
- package/src/bundler/adds/ToBundledJSPlugin.mjs +116 -55
- package/src/bundler/adds/autoExternalize.mjs +81 -0
- package/src/bundler/adds/emptyBufferValue.mjs +5 -0
- package/src/bundler/adds/isModuleTheBundledVersion.mjs +10 -0
- package/src/bundler/adds/onEndEsBuildErrorLogger.mjs +34 -0
- package/src/bundler/adds/resolveJSDependencyPath.mjs +17 -0
- package/src/class/AwaitSignal.mjs +119 -0
- package/src/class/Console.mjs +36 -14
- package/src/class/DataLog.mjs +29 -0
- package/src/class/Derived.mjs +67 -55
- package/src/class/Effect.mjs +270 -84
- package/src/class/EnvSignal.mjs +11 -8
- package/src/class/EsWatcher.mjs +60 -0
- package/src/class/EventSignal.mjs +46 -58
- package/src/class/FSDirArchWatcher.mjs +246 -0
- package/src/class/FileSafe.mjs +72 -24
- package/src/class/ForEach.mjs +78 -0
- package/src/class/ForSignal.mjs +115 -0
- package/src/class/GetterSetter.mjs +40 -0
- package/src/class/JSONFileHandler.mjs +90 -0
- package/src/class/ListSignal.mjs +68 -26
- package/src/class/LitExp.mjs +59 -36
- package/src/class/ObjectSignal.mjs +225 -0
- package/src/class/Paths.mjs +56 -20
- package/src/class/Prettivy.mjs +51 -0
- package/src/class/QChannel.mjs +48 -26
- package/src/class/SafeExit.mjs +156 -99
- package/src/class/Setup.mjs +28 -16
- package/src/class/Signal.mjs +50 -27
- package/src/class/SignalCollection.mjs +130 -0
- package/src/class/WalkThrough.mjs +6 -23
- package/src/class/{WorkerMainThreadBundled.mjs → WorkerMainThread.bundled.mjs} +56 -77
- package/src/class/WorkerMainThread.mjs +98 -94
- package/src/class/WorkerThread.mjs +24 -17
- package/src/common/Base64URL.mjs +6 -3
- package/src/common/Base64URLFromFile.mjs +17 -4
- package/src/common/BundledV.bundled.mjs +7 -0
- package/src/common/BundledV.mjs +45 -0
- package/src/common/CreateStringID.mjs +8 -7
- package/src/common/EnvMode.mjs +172 -0
- package/src/common/FactoryKey.mjs +11 -0
- package/src/common/Preferrence.mjs +27 -0
- package/src/common/Trace.mjs +1 -1
- package/src/common/TracePath.mjs +53 -3
- package/src/common/VivthUnBundledCodeBlock.mjs +8 -0
- package/src/doc/JSautoDOC.mjs +673 -284
- package/src/doc/cleanPreserveTypedef.mjs +27 -0
- package/src/doc/correctBeforeParse.mjs +57 -48
- package/src/doc/{parsedFile.mjs → parsedFileForDOC.mjs} +133 -120
- package/src/function/ClearRequireCache.mjs +33 -0
- package/src/function/CreateImmutable.mjs +40 -37
- package/src/function/EventCheck.mjs +5 -2
- package/src/function/EventObject.mjs +2 -6
- package/src/function/ForInAsync.mjs +76 -0
- package/src/function/ForInSync.mjs +87 -0
- package/src/function/ForOfAsync.mjs +61 -0
- package/src/function/ForOfSync.mjs +70 -0
- package/src/function/GetBufferFromRelativePath.mjs +25 -0
- package/src/function/GetFilesFromDir.mjs +49 -0
- package/src/function/GetMaxFilenameLength.mjs +32 -0
- package/src/function/GetModuleEsbuildPlatform.mjs +118 -0
- package/src/function/GetNamedImportAlias.mjs +2 -2
- package/src/function/GetRuntime.mjs +10 -14
- package/src/function/InstantiateAssemblyScript.mjs +22 -0
- package/src/function/IsAsync.mjs +1 -1
- package/src/function/IsInstanceOf.mjs +29 -0
- package/src/function/IsSameFile.mjs +41 -0
- package/src/function/IsStringLooksLikeAPath.mjs +20 -0
- package/src/function/IsTypeOf.mjs +27 -0
- package/src/function/IsTypeOf.mts +31 -0
- package/src/function/LazyFactory.mjs +25 -23
- package/src/function/MonkeyPatch.mjs +38 -0
- package/src/function/NewAnimationTimeline.mjs +55 -0
- package/src/function/NewChainable.mjs +69 -0
- package/src/function/NewDynamicsExport.mjs +312 -0
- package/src/function/NewObjectWrapper.mjs +14 -0
- package/src/function/ObjectRegistrar.mjs +23 -0
- package/src/function/ParseSQLFile.mjs +129 -0
- package/src/function/PipeAsync.mjs +30 -0
- package/src/function/PipeSync.mjs +28 -0
- package/src/function/SafeImport.mjs +77 -0
- package/src/function/TemplateLiteral.mjs +42 -23
- package/src/function/Timeout.mjs +4 -4
- package/src/function/Tries.mjs +22 -16
- package/src/function/TryAsync.mjs +3 -2
- package/src/function/TryNew.mjs +1 -1
- package/src/function/TsToMjs.mjs +184 -21
- package/src/function/UniqueFSTempName.mjs +33 -0
- package/src/function/errorToMessage.mjs +21 -0
- package/src/function/resolveErrorArray.mjs +15 -1
- package/src/neinth/VivthyNeinth.mjs +487 -0
- package/src/typehints/ArrayToKeys.mjs +17 -0
- package/src/typehints/ArrayToKeys.mts +31 -0
- package/src/typehints/AssemblyScriptExportsType.mjs +7 -0
- package/src/typehints/AssemblyScriptLoaderInstantiate.mjs +7 -0
- package/src/typehints/AutoDocASOptions.mjs +14 -0
- package/src/typehints/ChainableType.mjs +11 -0
- package/src/typehints/ComponentDecorator_Constructor.mjs +10 -0
- package/src/typehints/ConsoleAdditionalSettingType.mjs +6 -0
- package/src/typehints/Decorator.mjs +9 -0
- package/src/typehints/Decorator.mts +31 -0
- package/src/typehints/DecoratorMonkeyPatch.mjs +10 -0
- package/src/typehints/DecoratorMonkeyPatch.mts +43 -0
- package/src/{types → typehints}/DevTestCB.mjs +2 -2
- package/src/typehints/EnvModeType.mjs +6 -0
- package/src/{types → typehints}/ListArg.mjs +1 -1
- package/src/{types → typehints}/LitExpResultType.mjs +1 -1
- package/src/typehints/MonkeyPatchedType.mjs +13 -0
- package/src/typehints/ParametersFollowingN.mjs +8 -0
- package/src/typehints/ParametersFollowingN.mts +17 -0
- package/src/typehints/PrefixedKeysOf.mjs +9 -0
- package/src/typehints/Runtime.mjs +6 -0
- package/src/typehints/SafeImportReturnType.mjs +6 -0
- package/src/typehints/StylePropRefType.mjs +12 -0
- package/src/typehints/TemplateLiteralValueHandler.mjs +14 -0
- package/src/typehints/VLifecycleCallbacks.mjs +10 -0
- package/src/typehints/VivthCleanup.mjs +14 -0
- package/src/web/BrowserDirMapper.mjs +255 -0
- package/src/web/EnsureValidTag.mjs +5 -0
- package/src/web/EnsureValidTag.mts +10 -0
- package/src/web/ViteAddDynamics.mjs +34 -0
- package/src/web/ViteGetAllHTMLFile.mjs +97 -0
- package/src/web/WC_extendsA.mjs +330 -0
- package/src/web/WC_extendsB.mjs +332 -0
- package/src/web/bindings/WC_StyleProp_bind.mjs +70 -0
- package/src/web/bindings/WC_createElement_bind.mjs +95 -0
- package/src/web/bindings/WC_createNamedSlot.mjs +29 -0
- package/src/web/bindings/WC_litRender_bind.mjs +26 -0
- package/src/web/bindings/WC_litStyleMap.mjs +14 -0
- package/src/web/common/CSS.mjs +35 -0
- package/src/web/common/E.mjs +126 -0
- package/src/web/common/NewStyleSheetAsync.mjs +21 -0
- package/src/web/common/NewStyleSheetSync.mjs +21 -0
- package/src/web/common/WC_TagName_type.mjs +10 -0
- package/src/web/common/WC_TagName_type.mts +36 -0
- package/src/web/signals/IsInViewPortSignal.mjs +140 -0
- package/src/web/signals/ObserverSignal.mjs +93 -0
- package/src/web/signals/WC_litRef.mjs +61 -0
- package/src/web/signals/WC_loopedSiblingsRef.mjs +100 -0
- package/tsconfig.json +44 -41
- package/index.mjs +0 -91
- package/src/bundler/FSInline.mjs +0 -67
- package/src/bundler/FSInlineAnalyzer.mjs +0 -228
- package/src/bundler/FSInlineBundled.mjs +0 -38
- package/src/bundler/adds/externals.mjs +0 -8
- package/src/class/ListDerived.mjs +0 -42
- package/src/common/Dev.mjs +0 -142
- package/src/common/DevBundled.mjs +0 -5
- package/src/common/lazie.mjs +0 -3
- package/src/types/IsListSignal.mjs +0 -6
- package/src/types/Runtime.mjs +0 -6
- package/src/types/VivthDevCodeBlockStringType.mjs +0 -6
- package/types/index.d.mts +0 -58
- package/types/src/bundler/CompileJS.d.mts +0 -119
- package/types/src/bundler/FSInline.d.mts +0 -50
- package/types/src/bundler/FSInlineAnalyzer.d.mts +0 -37
- package/types/src/bundler/FSInlineBundled.d.mts +0 -22
- package/types/src/bundler/adds/externals.d.mts +0 -1
- package/types/src/class/Console.d.mts +0 -71
- package/types/src/class/Derived.d.mts +0 -98
- package/types/src/class/Effect.d.mts +0 -216
- package/types/src/class/ListDerived.d.mts +0 -38
- package/types/src/class/Paths.d.mts +0 -69
- package/types/src/class/SafeExit.d.mts +0 -103
- package/types/src/class/WorkerMainThreadBundled.d.mts +0 -83
- package/types/src/common/Base64URLFromFile.d.mts +0 -16
- package/types/src/common/Dev.d.mts +0 -68
- package/types/src/common/DevBundled.d.mts +0 -3
- package/types/src/common/lazie.d.mts +0 -1
- package/types/src/doc/JSautoDOC.d.mts +0 -83
- package/types/src/function/GetRuntime.d.mts +0 -2
- package/types/src/function/TemplateLiteral.d.mts +0 -22
- package/types/src/function/TsToMjs.d.mts +0 -23
- package/types/src/types/IsListSignal.d.mts +0 -4
- package/types/src/types/ListArg.d.mts +0 -4
- package/types/src/types/Runtime.d.mts +0 -4
- package/types/src/types/VivthDevCodeBlockStringType.d.mts +0 -4
- /package/{types → generated/types}/src/bundler/adds/pluginVivthBundle.d.mts +0 -0
- /package/{types → generated/types}/src/class/WorkerResult.d.mts +0 -0
- /package/{types → generated/types}/src/common/EventNameSpace.d.mts +0 -0
- /package/{types → generated/types}/src/common/eventObjects.d.mts +0 -0
- /package/{types → generated/types}/src/common/keys.d.mts +0 -0
- /package/{types → generated/types}/src/doc/correctBeforeParse.d.mts +0 -0
- /package/{types → generated/types}/src/function/TrySync.d.mts +0 -0
- /package/{types → generated/types}/src/function/resolveErrorArray.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/AnyButUndefined.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/ExtnameType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/LitExpKeyType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/LitExpResultType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/MutationType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/QCBFIFOReturn.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/QCBReturn.d.mts +0 -0
- /package/src/{types → typehints}/AnyButUndefined.mjs +0 -0
- /package/src/{types → typehints}/ExtnameType.mjs +0 -0
- /package/src/{types → typehints}/LitExpKeyType.mjs +0 -0
- /package/src/{types → typehints}/MutationType.mjs +0 -0
- /package/src/{types → typehints}/QCBFIFOReturn.mjs +0 -0
- /package/src/{types → typehints}/QCBReturn.mjs +0 -0
package/src/class/Derived.mjs
CHANGED
|
@@ -3,31 +3,37 @@
|
|
|
3
3
|
import { Signal } from './Signal.mjs';
|
|
4
4
|
import { Console } from './Console.mjs';
|
|
5
5
|
import { Effect } from './Effect.mjs';
|
|
6
|
-
import { LazyFactory } from '../function/LazyFactory.mjs';
|
|
7
|
-
import { unwrapLazy } from '../common/lazie.mjs';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* @description
|
|
11
9
|
* - a class for creating derived version of [Signal](#signal);
|
|
12
10
|
* @template VALUE
|
|
13
|
-
* @extends Signal<VALUE>
|
|
11
|
+
* @extends Signal<VALUE|undefined>
|
|
14
12
|
*/
|
|
15
13
|
export class Derived extends Signal {
|
|
16
14
|
/**
|
|
17
15
|
* @description
|
|
18
16
|
* - Derived used [Signal](#signal) and [Effect](#effect) under the hood;
|
|
19
|
-
* @param {(
|
|
20
|
-
*
|
|
21
|
-
*
|
|
17
|
+
* @param {(
|
|
18
|
+
* effectInstanceOptions: Parameters<ConstructorParameters<typeof Effect>[0]>[0] &
|
|
19
|
+
* {
|
|
20
|
+
* dontUpdate:Derived<VALUE>["dontUpdate"]
|
|
21
|
+
* }
|
|
22
|
+
* ) => Promise<Derived<VALUE>["dontUpdate"] | VALUE>
|
|
23
|
+
* } derivedFunction
|
|
24
|
+
* @param {ConstructorParameters<typeof Effect>[1]} [maxTimelapseBeingDebounced]
|
|
25
|
+
* - prevent rapid changes from being unhandled more than the value;
|
|
26
|
+
* - in miliseconds;
|
|
27
|
+
* - default: `2_000`;
|
|
22
28
|
* @example
|
|
23
|
-
* import { Signal, Derived } from
|
|
29
|
+
* import { Signal, Derived } from 'vivth/neutral';
|
|
24
30
|
*
|
|
25
31
|
* const count = new Signal(0);
|
|
26
32
|
* const double = new Derived(async({
|
|
27
33
|
* subscribe,
|
|
28
34
|
* // : registrar callback for this derived instance, immediately return the signal instance
|
|
29
35
|
* }) => {
|
|
30
|
-
* return subscribe(count).value
|
|
36
|
+
* return subscribe(count).value \* 2;
|
|
31
37
|
* // double listen to count changes, by returning the value, double.value also changes
|
|
32
38
|
* // notice the count.value are accessed double, but it's all safe,
|
|
33
39
|
* // since the wrapped one is the only one that are recorded as notifier.
|
|
@@ -35,64 +41,70 @@ export class Derived extends Signal {
|
|
|
35
41
|
*
|
|
36
42
|
* count.value++;
|
|
37
43
|
*/
|
|
38
|
-
constructor(derivedFunction) {
|
|
39
|
-
// @ts-expect-error
|
|
44
|
+
constructor(derivedFunction, maxTimelapseBeingDebounced = undefined) {
|
|
40
45
|
super(undefined);
|
|
41
|
-
const derived_instanceOptions = this.options;
|
|
42
46
|
new Effect(async (options) => {
|
|
43
|
-
const currentValue = await derivedFunction(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (currentValue === derived_instanceOptions.dontUpdate) {
|
|
47
|
+
const currentValue = await derivedFunction(
|
|
48
|
+
Object.assign(options, { dontUpdate: this.dontUpdate }),
|
|
49
|
+
);
|
|
50
|
+
if (currentValue === this.dontUpdate) {
|
|
48
51
|
return;
|
|
49
52
|
}
|
|
53
|
+
// @ts-expect-error
|
|
50
54
|
super.value = currentValue;
|
|
51
|
-
});
|
|
55
|
+
}, maxTimelapseBeingDebounced);
|
|
52
56
|
}
|
|
53
57
|
/**
|
|
54
58
|
* @description
|
|
55
|
-
* -
|
|
59
|
+
* - return this value to not to update the value of this instance, even when returning early;
|
|
60
|
+
* @type {Symbol}
|
|
61
|
+
* @example
|
|
62
|
+
* import { Signal, Derived } from 'vivth/neutral';
|
|
63
|
+
*
|
|
64
|
+
* const count = new Signal(0);
|
|
65
|
+
* const double = new Derived(async({
|
|
66
|
+
* subscribe,
|
|
67
|
+
* isLastCalled,
|
|
68
|
+
* }) => {
|
|
69
|
+
* if(!(await isLastCalled(100))) {
|
|
70
|
+
* return this.dontUpdate;
|
|
71
|
+
* }
|
|
72
|
+
* const currentValue = subscribe(count).value;
|
|
73
|
+
* const res = await fetch(`some/path/${curentValue.toString()}`);
|
|
74
|
+
* if (
|
|
75
|
+
* !(await isLastCalled()) ||
|
|
76
|
+
* !res
|
|
77
|
+
* ) {
|
|
78
|
+
* // returning early prevent race condition, even if the earlier fetch return late;
|
|
79
|
+
* return this.dontUpdate;
|
|
80
|
+
* // returning this.dontUpdate, will not modify the derived instance value;
|
|
81
|
+
* }
|
|
82
|
+
* count.value++;
|
|
83
|
+
* return res;
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
56
86
|
*/
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
/**
|
|
60
|
-
* @instance options
|
|
61
|
-
* @description
|
|
62
|
-
* - return this value tandem with `isLastCalled`, to not to update the value of this instance, even when returning early;
|
|
63
|
-
* @type {Object}
|
|
64
|
-
* @example
|
|
65
|
-
* import { Signal, Derived } from 'vivth';
|
|
66
|
-
*
|
|
67
|
-
* const count = new Signal(0);
|
|
68
|
-
* const double = new Derived(async({
|
|
69
|
-
* subscribe,
|
|
70
|
-
* dontUpdate,
|
|
71
|
-
* isLastCalled,
|
|
72
|
-
* }) => {
|
|
73
|
-
* const currentValue = subscribe(count).value;
|
|
74
|
-
* if (!(await isLastCalled(10))) {
|
|
75
|
-
* return dontUpdate;
|
|
76
|
-
* }
|
|
77
|
-
* const res = await fetch(`some/path/${curentValue.toString()}`);
|
|
78
|
-
* if (!(await isLastCalled())) {
|
|
79
|
-
* return dontUpdate; // this will prevent race condition, even if the earlier fetch return late;
|
|
80
|
-
* }
|
|
81
|
-
* return res;
|
|
82
|
-
* });
|
|
83
|
-
*
|
|
84
|
-
* count.value++;
|
|
85
|
-
*/
|
|
86
|
-
dontUpdate: {},
|
|
87
|
-
};
|
|
88
|
-
});
|
|
87
|
+
dontUpdate = Symbol('');
|
|
89
88
|
/**
|
|
90
89
|
* @description
|
|
91
|
-
* - the most recent value of the instance
|
|
90
|
+
* - the most recent value of the instance;
|
|
92
91
|
* - can be turn into reactive with Effect or Derived instantiation;
|
|
93
|
-
* -
|
|
94
|
-
*
|
|
92
|
+
* - value are allowed to be `undefined` and always be `undefined` at the instantiation time;
|
|
93
|
+
* >- make sure to put a check before consuming(inside an `Effect`);
|
|
94
|
+
* @returns {VALUE|undefined}
|
|
95
95
|
* @override
|
|
96
|
+
* @example
|
|
97
|
+
* import { Signal, Derived, Effect } from 'vivth/neutral';
|
|
98
|
+
*
|
|
99
|
+
* const numberSignal = new Signal(0);
|
|
100
|
+
* const doubleDerived = new Derived(async({ subscribe }) => {
|
|
101
|
+
* return subscribe(numberSignal).value \* 2;
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* new Effect(async({ subscribe }) => {
|
|
105
|
+
* console.log(subscribe(doubleDerived).value);
|
|
106
|
+
* })
|
|
107
|
+
* numberSignal++;
|
|
96
108
|
*/
|
|
97
109
|
get value() {
|
|
98
110
|
return super.value;
|
|
@@ -100,9 +112,9 @@ export class Derived extends Signal {
|
|
|
100
112
|
/**
|
|
101
113
|
* @description
|
|
102
114
|
* - Derived instance value cannot be manually assigned;
|
|
103
|
-
* - it's value should always be determined by it's own `derivedFunction`;
|
|
115
|
+
* - it's value should always be determined by it's own returned value from `derivedFunction`;
|
|
104
116
|
* @private
|
|
105
|
-
* @type {VALUE}
|
|
117
|
+
* @type {(value:VALUE|undefined)=>void}
|
|
106
118
|
* @override
|
|
107
119
|
*/
|
|
108
120
|
set value(newValue) {
|
package/src/class/Effect.mjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import { unwrapLazy } from '../common/lazie.mjs';
|
|
4
3
|
import { WalkThrough } from './WalkThrough.mjs';
|
|
5
4
|
import { LazyFactory } from '../function/LazyFactory.mjs';
|
|
6
5
|
import { Timeout } from '../function/Timeout.mjs';
|
|
7
6
|
import { TryAsync } from '../function/TryAsync.mjs';
|
|
8
7
|
import { Console } from './Console.mjs';
|
|
9
8
|
import { Signal } from './Signal.mjs';
|
|
10
|
-
|
|
9
|
+
import { ForInSync } from '../function/ForInSync.mjs';
|
|
10
|
+
import { FactoryKey } from '../common/FactoryKey.mjs';
|
|
11
|
+
import { IsInstanceOf } from '../function/IsInstanceOf.mjs';
|
|
12
|
+
import { ForOfSync } from '../function/ForOfSync.mjs';
|
|
13
|
+
/**
|
|
14
|
+
* @typedef { import('../typehints/VivthCleanup.mjs').VivthCleanup } VivthCleanup
|
|
15
|
+
*/
|
|
11
16
|
/**
|
|
12
17
|
* @type {Map<Effect, Set<Signal<any>>>}
|
|
13
18
|
*/
|
|
@@ -16,19 +21,55 @@ export const mapOfEffects = new Map();
|
|
|
16
21
|
/**
|
|
17
22
|
* @description
|
|
18
23
|
* - a class for creating effect;
|
|
19
|
-
* -
|
|
24
|
+
* - behaviour:
|
|
20
25
|
* >- doesn't autosubscribe at first run;
|
|
21
|
-
* >- it is using passed <b
|
|
22
|
-
* >- doesn't block other queues during first run
|
|
23
|
-
* >-
|
|
26
|
+
* >- it is using passed <b>subscribe</b> named `arg0` options as subscriber;
|
|
27
|
+
* >- doesn't block other queues during first run;
|
|
28
|
+
* >- can dynamically subscribes to signal, even on conditionals, that are not run during first run;
|
|
29
|
+
* @implements {VivthCleanup}
|
|
24
30
|
*/
|
|
25
31
|
export class Effect {
|
|
32
|
+
vivthCleanup = async () => {
|
|
33
|
+
this.options.removeEffect();
|
|
34
|
+
};
|
|
26
35
|
/**
|
|
27
|
-
* @
|
|
36
|
+
* @description
|
|
37
|
+
* @param {(
|
|
38
|
+
* arg0: Effect["options"]
|
|
39
|
+
* ) => Promise<void>
|
|
40
|
+
* } effect
|
|
41
|
+
* @param {number} [maxTimelapseBeingDebounced]
|
|
42
|
+
* - prevent rapid changes from being unhandled more than the value;
|
|
43
|
+
* - in miliseconds;
|
|
44
|
+
* - default: `2_000`;
|
|
45
|
+
* @example
|
|
46
|
+
* import { Signal, Derived, Effect, Console } from 'vivth/neutral';
|
|
47
|
+
*
|
|
48
|
+
* const count = new Signal(0);
|
|
49
|
+
*
|
|
50
|
+
* // double listen to count changes
|
|
51
|
+
* const double = new Derived(async({subscribe}) => subscribe(count).value \* 2);
|
|
52
|
+
*
|
|
53
|
+
* new Effect(async ({
|
|
54
|
+
* subscribe, // : registrar callback for this effect instance, immediately return the signal instance
|
|
55
|
+
* removeEffect, // : disable this effect instance from reacting to dependency changes;
|
|
56
|
+
* isLastCalled, // : check whether this callback run is this instance last called effect;
|
|
57
|
+
* }) => {
|
|
58
|
+
* const { value: currentValue, prev: prevValue } = subscribe(double); // effect listen to double changes
|
|
59
|
+
* Console.log({ currentValue, prevValue });
|
|
60
|
+
* })
|
|
61
|
+
*
|
|
62
|
+
* count.value++;
|
|
28
63
|
*/
|
|
64
|
+
constructor(effect, maxTimelapseBeingDebounced = 2_000) {
|
|
65
|
+
this.#maxTimelapseBeingDebounced = maxTimelapseBeingDebounced;
|
|
66
|
+
this.#effect = effect;
|
|
67
|
+
mapOfEffects.set(this, new Set());
|
|
68
|
+
this.run();
|
|
69
|
+
}
|
|
29
70
|
/**
|
|
30
71
|
* @description
|
|
31
|
-
* - collections of
|
|
72
|
+
* - collections of methods to handle effect calls of this instance;
|
|
32
73
|
*/
|
|
33
74
|
options = LazyFactory(() => {
|
|
34
75
|
const this_ = this;
|
|
@@ -36,59 +77,56 @@ export class Effect {
|
|
|
36
77
|
/**
|
|
37
78
|
* @instance options
|
|
38
79
|
* @description
|
|
39
|
-
*
|
|
40
|
-
* -
|
|
41
|
-
*
|
|
80
|
+
* - subscribe to `Signal_instance`;
|
|
81
|
+
* - normally it's passed as argument to constructor, however it is also accessible from `options` property;
|
|
82
|
+
* @template {Signal<any>} SIGV
|
|
83
|
+
* @param {SIGV} signalInstance
|
|
84
|
+
* @returns {SIGV}
|
|
42
85
|
* @example
|
|
86
|
+
* import { Signal, Effect } from 'vivth/neutral';
|
|
43
87
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* const
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* if (!(await isLastCalled(
|
|
53
|
-
* // no need to add timeoutMS argument, as fetch are naturally add delay;
|
|
54
|
-
* ))) {
|
|
55
|
-
* return;
|
|
88
|
+
* const signal1 = new Signal(0);
|
|
89
|
+
* const signal2 = new Signal(true);
|
|
90
|
+
* const signal3 = new Signal(true);
|
|
91
|
+
* const effect = new Effect(async ({ subscribe }) => {
|
|
92
|
+
* const signal1Value = subscribe(signal1).value;
|
|
93
|
+
* if(signal1Value % 2){
|
|
94
|
+
* // only subscribe to signal3, on conditional block
|
|
95
|
+
* const signal3Value = subscribe(signal3).value;
|
|
56
96
|
* }
|
|
57
97
|
* })
|
|
98
|
+
* effect.options.subscribe(signal2);
|
|
58
99
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
return current === this_.#current;
|
|
67
|
-
};
|
|
100
|
+
subscribe: (signalInstance) => {
|
|
101
|
+
if (!IsInstanceOf(signalInstance, Signal)) {
|
|
102
|
+
signalInstance = signalInstance[FactoryKey];
|
|
103
|
+
}
|
|
104
|
+
signalInstance.subscribers.setOf.add(this_);
|
|
105
|
+
return signalInstance;
|
|
68
106
|
},
|
|
69
107
|
/**
|
|
70
108
|
* @instance options
|
|
71
109
|
* @description
|
|
72
|
-
* - subscribe
|
|
110
|
+
* - the same with `.options.subscribe`, but for batches subscription;
|
|
111
|
+
* - ideal for first run which to add signal to subscription on main condition;
|
|
73
112
|
* - normally it's passed as argument to constructor, however it is also accessible from `options` property;
|
|
74
|
-
* @template
|
|
75
|
-
* @param {
|
|
76
|
-
* @returns {
|
|
113
|
+
* @template {ReadonlyArray<any>} T
|
|
114
|
+
* @param {T} signalInstances
|
|
115
|
+
* @returns {T}
|
|
77
116
|
* @example
|
|
78
|
-
* import { Effect } from 'vivth';
|
|
117
|
+
* import { Signal, Effect } from 'vivth/neutral';
|
|
79
118
|
*
|
|
80
|
-
* const
|
|
81
|
-
*
|
|
119
|
+
* const signal1 = new Signal(0);
|
|
120
|
+
* const signal2 = new Signal(true);
|
|
121
|
+
* const effect = new Effect(async ({ subscribes }) => {
|
|
122
|
+
* const [{value: signal1Value}, {value: signal2Value}]= subscribes([signal1, signal2]);
|
|
82
123
|
* })
|
|
83
|
-
* effect.options.subscribe(signalInstance);
|
|
84
124
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
signalInstance.subscribers.setOf.add(this_);
|
|
91
|
-
return signalInstance;
|
|
125
|
+
subscribes: (signalInstances) => {
|
|
126
|
+
ForOfSync(signalInstances, (signal) => {
|
|
127
|
+
this.options.subscribe(signal).value;
|
|
128
|
+
});
|
|
129
|
+
return signalInstances;
|
|
92
130
|
},
|
|
93
131
|
/**
|
|
94
132
|
* @instance options
|
|
@@ -96,11 +134,15 @@ export class Effect {
|
|
|
96
134
|
* - normally it's passed as argument to constructor, however it is also accessible from `options` property;
|
|
97
135
|
* @type {()=>void}
|
|
98
136
|
* @example
|
|
99
|
-
* import { Effect } from 'vivth';
|
|
137
|
+
* import { Effect } from 'vivth/neutral';
|
|
100
138
|
*
|
|
101
|
-
* const effect = new Effect(async () => {
|
|
102
|
-
*
|
|
139
|
+
* const effect = new Effect(async ({removeEffect}) => {
|
|
140
|
+
* if(someCondition){
|
|
141
|
+
* removeEffect();
|
|
142
|
+
* return
|
|
143
|
+
* }
|
|
103
144
|
* })
|
|
145
|
+
* // OR
|
|
104
146
|
* effect.options.removeEffect();
|
|
105
147
|
*/
|
|
106
148
|
removeEffect: () => {
|
|
@@ -121,7 +163,7 @@ export class Effect {
|
|
|
121
163
|
* @param {Signal<any>} signalInstance
|
|
122
164
|
* @returns {void}
|
|
123
165
|
* @example
|
|
124
|
-
* import { Effect, Signal } from 'vivth';
|
|
166
|
+
* import { Effect, Signal } from 'vivth/neutral';
|
|
125
167
|
*
|
|
126
168
|
* const count = new Signal(0);
|
|
127
169
|
* const effect = new Effect(async ({ subscribe }) => {
|
|
@@ -143,50 +185,188 @@ export class Effect {
|
|
|
143
185
|
}
|
|
144
186
|
mapOfEffects.delete(this);
|
|
145
187
|
},
|
|
188
|
+
/**
|
|
189
|
+
* @description
|
|
190
|
+
* - remove inputed `SignalCollection` from this `Effect_instance`;
|
|
191
|
+
* - normally it's passed as argument to constructor, however it is also accessible from `options` property;
|
|
192
|
+
* @param {import('./SignalCollection.mjs').SignalCollection<Record<string, Signal<any>>>} collectionInstance
|
|
193
|
+
* @returns {void}
|
|
194
|
+
* @example
|
|
195
|
+
* import { Signal, Derived, Effect, SignalCollection } from 'vivth/neutral';
|
|
196
|
+
*
|
|
197
|
+
* const a = new Signal('a');
|
|
198
|
+
* const b = new Signal('b');
|
|
199
|
+
* const c = new Derived(async ({ subscribe }) => {
|
|
200
|
+
* return `${subscribe(b).value}_b`;
|
|
201
|
+
* });
|
|
202
|
+
* const f = new SignalCollection({ a, c });
|
|
203
|
+
*
|
|
204
|
+
* const e = new Effect(async ({ subscribe, isLastCalled, removeCollection }) => {
|
|
205
|
+
* const {
|
|
206
|
+
* a: { value: aa }, // safely desctructured and auto subscribed
|
|
207
|
+
* c: { value: cc }, // safely desctructured and auto subscribed
|
|
208
|
+
* } = f.signals(subscribe);
|
|
209
|
+
* if(!await isLastCalled(100)) {
|
|
210
|
+
* return; // impertaive debounce
|
|
211
|
+
* }
|
|
212
|
+
* // removeCollection(f); // standard call from outside callback;
|
|
213
|
+
* });
|
|
214
|
+
* // optional call from outside callback;
|
|
215
|
+
* e.options.removeCollection(f)
|
|
216
|
+
*/
|
|
217
|
+
removeCollection: (collectionInstance) => {
|
|
218
|
+
const collection = collectionInstance.signals();
|
|
219
|
+
const removeSignal = this.options.removeSignal;
|
|
220
|
+
ForInSync(collection, (_key, signal) => {
|
|
221
|
+
removeSignal(signal);
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
/**
|
|
225
|
+
* @instance options
|
|
226
|
+
* @description
|
|
227
|
+
* @returns {(timeoutMS?:number)=>Promise<boolean>}
|
|
228
|
+
* - timeoutMS only necessary if the operation doesn't naturally await;
|
|
229
|
+
* - if it's operation such as `fetch`, you can just leave it blank;
|
|
230
|
+
* @example
|
|
231
|
+
*
|
|
232
|
+
* import { Effect } from 'vivth/neutral';
|
|
233
|
+
*
|
|
234
|
+
* const effect = new Effect(async ({ isLastCalled }) => {
|
|
235
|
+
* if (!(await isLastCalled(100))) {
|
|
236
|
+
* return;
|
|
237
|
+
* }
|
|
238
|
+
* // OR
|
|
239
|
+
* const res = await fetch('some/path');
|
|
240
|
+
* if (!(await isLastCalled(
|
|
241
|
+
* // no need to add timeoutMS argument, as fetch are naturally add delay;
|
|
242
|
+
* ))) {
|
|
243
|
+
* return;
|
|
244
|
+
* }
|
|
245
|
+
* })
|
|
246
|
+
*/
|
|
247
|
+
get isLastCalled() {
|
|
248
|
+
const current = this_.#current;
|
|
249
|
+
let isRealyEnforced = false;
|
|
250
|
+
return async (timeoutMS = 0) => {
|
|
251
|
+
const firstTimeDebounced = this_.#firstTimeDebounced;
|
|
252
|
+
if (isRealyEnforced) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
if (timeoutMS) {
|
|
256
|
+
await Timeout(timeoutMS);
|
|
257
|
+
}
|
|
258
|
+
if (!(await this_.#shallowCurrentCheck(current))) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
const [isLast, isEnforced] = await this_.#deepCurrentCheck(current, firstTimeDebounced);
|
|
262
|
+
if (isEnforced) {
|
|
263
|
+
isRealyEnforced = true;
|
|
264
|
+
this_.#promiser(current);
|
|
265
|
+
}
|
|
266
|
+
return isLast;
|
|
267
|
+
};
|
|
268
|
+
},
|
|
146
269
|
};
|
|
147
270
|
});
|
|
148
271
|
/**
|
|
149
|
-
* @
|
|
150
|
-
* @
|
|
151
|
-
* Omit<Effect["options"], typeof unwrapLazy>
|
|
152
|
-
* ) =>
|
|
153
|
-
* Promise<void>} effect
|
|
154
|
-
* @example
|
|
155
|
-
* import { Signal, Derived, Effect, Console } from 'vivth';
|
|
156
|
-
*
|
|
157
|
-
* const count = new Signal(0);
|
|
158
|
-
* const double = new Derived( async({$}) => $(count).value \* 2); // double listen to count changes
|
|
159
|
-
* new Effect(async ({
|
|
160
|
-
* subscribe, // : registrar callback for this effect instance, immediately return the signal instance
|
|
161
|
-
* removeEffect, // : disable this effect instance from reacting to dependency changes;
|
|
162
|
-
* isLastCalled, // : check whether this callback run is this instant last called effect;
|
|
163
|
-
* }) => {
|
|
164
|
-
* Console.log(subscribe(double).value); // effect listen to double changes
|
|
165
|
-
* const a = double.value; // no need to wrap double twice with $
|
|
166
|
-
* })
|
|
167
|
-
*
|
|
168
|
-
* count.value++;
|
|
272
|
+
* @param {Object} current
|
|
273
|
+
* @returns {void}
|
|
169
274
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
275
|
+
#promiser = (current) => {
|
|
276
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
277
|
+
this.#promise = promise;
|
|
278
|
+
const cleanupCallback = () => {
|
|
279
|
+
resolve(true);
|
|
280
|
+
this.#promise = undefined;
|
|
281
|
+
Effect.#mapCurrentCleanupCallback.delete(current);
|
|
282
|
+
};
|
|
283
|
+
Effect.#mapCurrentCleanupCallback.set(current, cleanupCallback);
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* @type {undefined|Promise<any>}
|
|
287
|
+
*/
|
|
288
|
+
#promise = undefined;
|
|
175
289
|
/**
|
|
176
290
|
* @type {Object}
|
|
177
291
|
*/
|
|
178
292
|
#current = {};
|
|
179
293
|
/**
|
|
180
|
-
* @
|
|
181
|
-
|
|
294
|
+
* @type {WeakMap<Object, ()=>void>}
|
|
295
|
+
*/
|
|
296
|
+
static #mapCurrentCleanupCallback = new WeakMap();
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @type {number|undefined}
|
|
300
|
+
*/
|
|
301
|
+
#firstTimeDebounced_ = undefined;
|
|
302
|
+
get #firstTimeDebounced() {
|
|
303
|
+
if (!this.#firstTimeDebounced_) {
|
|
304
|
+
this.#firstTimeDebounced_ = Date.now();
|
|
305
|
+
}
|
|
306
|
+
return this.#firstTimeDebounced_;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* @type {number}
|
|
310
|
+
*/
|
|
311
|
+
#maxTimelapseBeingDebounced;
|
|
312
|
+
/**
|
|
313
|
+
* @param {Object} current
|
|
314
|
+
* @returns {boolean}
|
|
315
|
+
*/
|
|
316
|
+
#shallowerCurrentCheck_ = (current) => {
|
|
317
|
+
if (this.#current === current) {
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
this.#firstTimeDebounced_ = undefined;
|
|
321
|
+
return false;
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* @param {Object} current
|
|
325
|
+
* @returns {Promise<boolean>}
|
|
326
|
+
*/
|
|
327
|
+
#shallowCurrentCheck = async (current) => {
|
|
328
|
+
if (!this.#shallowerCurrentCheck_(current)) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
if (this.#promise) {
|
|
332
|
+
await this.#promise;
|
|
333
|
+
if (!this.#shallowerCurrentCheck_(current)) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return true;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* @param {Object} current
|
|
341
|
+
* @param {number} chacedFirstTimeDebounced
|
|
342
|
+
* @returns {Promise<[isLast:boolean, isEnforced:boolean]>}
|
|
343
|
+
*/
|
|
344
|
+
#deepCurrentCheck = async (current, chacedFirstTimeDebounced) => {
|
|
345
|
+
const elapsed = Date.now() - chacedFirstTimeDebounced;
|
|
346
|
+
let isLast;
|
|
347
|
+
let isEnforced;
|
|
348
|
+
if (elapsed >= this.#maxTimelapseBeingDebounced) {
|
|
349
|
+
isLast = true;
|
|
350
|
+
isEnforced = true;
|
|
351
|
+
} else {
|
|
352
|
+
isLast = current === this.#current;
|
|
353
|
+
isEnforced = false;
|
|
354
|
+
}
|
|
355
|
+
if (isLast) {
|
|
356
|
+
this.#firstTimeDebounced_ = undefined;
|
|
357
|
+
}
|
|
358
|
+
return [isLast, isEnforced];
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* @type {(effectCallback:Parameters<ConstructorParameters<typeof Effect>[0]>[0])=>Promise<void>}
|
|
182
362
|
*/
|
|
183
363
|
#effect;
|
|
184
364
|
/**
|
|
185
365
|
* @description
|
|
186
366
|
* - normally is to let to be automatically run when dependency signals changes, however it's also accessible as instance method;
|
|
187
|
-
* @
|
|
367
|
+
* @type {()=>void}
|
|
188
368
|
* @example
|
|
189
|
-
* import { Effect } from 'vivth';
|
|
369
|
+
* import { Effect } from 'vivth/neutral';
|
|
190
370
|
*
|
|
191
371
|
* const effect = new Effect(async ()=>{
|
|
192
372
|
* // code
|
|
@@ -194,6 +374,7 @@ export class Effect {
|
|
|
194
374
|
* effect.run();
|
|
195
375
|
*/
|
|
196
376
|
run = () => {
|
|
377
|
+
const current = {};
|
|
197
378
|
TryAsync(async () => {
|
|
198
379
|
if (
|
|
199
380
|
//
|
|
@@ -202,12 +383,17 @@ export class Effect {
|
|
|
202
383
|
this.options.removeEffect();
|
|
203
384
|
return;
|
|
204
385
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (error === undefined) {
|
|
386
|
+
const options = this.options[FactoryKey];
|
|
387
|
+
if (!options) {
|
|
208
388
|
return;
|
|
209
389
|
}
|
|
210
|
-
|
|
390
|
+
this.#current = current;
|
|
391
|
+
await this.#effect(options);
|
|
392
|
+
}).then(([, error]) => {
|
|
393
|
+
if (error) {
|
|
394
|
+
Console.error(error);
|
|
395
|
+
}
|
|
396
|
+
Effect.#mapCurrentCleanupCallback.get(current)?.(); // technically this line is a mock finally block
|
|
211
397
|
});
|
|
212
398
|
};
|
|
213
399
|
}
|
package/src/class/EnvSignal.mjs
CHANGED
|
@@ -15,15 +15,18 @@ export class EnvSignal {
|
|
|
15
15
|
* @description
|
|
16
16
|
* - create `EnvSignal` instance;
|
|
17
17
|
* @param {VALUE} initialValue
|
|
18
|
+
* @example
|
|
19
|
+
* import { EnvSignal } from 'vivth/neutral';
|
|
20
|
+
*
|
|
21
|
+
* export const myEnv = new EnvSignal(true);
|
|
18
22
|
*/
|
|
19
23
|
constructor(initialValue) {
|
|
20
24
|
this.#proxyConst = LazyFactory(() => new Signal(initialValue));
|
|
21
|
-
this.env = LazyFactory(
|
|
22
|
-
() =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
);
|
|
25
|
+
this.env = LazyFactory(() => {
|
|
26
|
+
return new Derived(async ({ subscribe }) => {
|
|
27
|
+
return subscribe(this.#proxyConst).value;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
27
30
|
}
|
|
28
31
|
#isModified = false;
|
|
29
32
|
/**
|
|
@@ -35,7 +38,7 @@ export class EnvSignal {
|
|
|
35
38
|
* - exposed property to listen to;
|
|
36
39
|
* @type {Derived<VALUE>}
|
|
37
40
|
* @example
|
|
38
|
-
* import { EnvSignal, Effect } from 'vivth';
|
|
41
|
+
* import { EnvSignal, Effect } from 'vivth/neutral';
|
|
39
42
|
*
|
|
40
43
|
* export const myEnv = new EnvSignal(true);
|
|
41
44
|
* new Effect(async ({ subscribe }) => {
|
|
@@ -51,7 +54,7 @@ export class EnvSignal {
|
|
|
51
54
|
* @param {VALUE} correctedValue
|
|
52
55
|
* @returns {void}
|
|
53
56
|
* @example
|
|
54
|
-
* import { EnvSignal } from 'vivth';
|
|
57
|
+
* import { EnvSignal } from 'vivth/neutral';
|
|
55
58
|
*
|
|
56
59
|
* export const myEnv = new EnvSignal(true);
|
|
57
60
|
*
|