From d90b2e53fd7b90547bf22f4a5539712fd1c776cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?He=CC=84sperus?= Date: Wed, 1 Jul 2026 13:14:25 +0800 Subject: [PATCH 1/2] feat(reactive): clean all subs --- src/context.ts | 13 +++++++------ src/reactive.ts | 6 ++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/context.ts b/src/context.ts index 32df462..b184e5f 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,9 +1,8 @@ type General = any; -type GeneralObject = object; type GeneralConstructor = new (...args: Array) => General; type ModuleConstructor = new (context: C) => General; -type GeneralModuleInput = ReadonlyArray | ReadonlyArray; +type GeneralModuleInput = ReadonlyArray | ReadonlyArray; type IsPlainObject = T extends object ? T extends Function | Date | RegExp | Array | Map | Set @@ -14,7 +13,7 @@ type IsPlainObject = T extends object type ShallowMerge = IsPlainObject extends true ? (IsPlainObject extends true ? Omit & B : B) : B; -type Keys = T extends any ? keyof T : never; +type Keys = T extends General ? keyof T : never; type InstanceEach = T extends ReadonlyArray ? { [K in keyof T]: InstanceType } : T; @@ -63,13 +62,15 @@ type MergeResult< > = MergeObjects<[Pr, ...PickEach, K>, Po]>; export type Context< - M extends ReadonlyArray>, + M extends GeneralModuleInput, K extends Keys[number]>, Pr extends object = {}, Po extends object = {}, > = MergeResult & { - __modules__: WeakMap>; - __getModule__: (ctor: C) => InstanceType; + __modules__: WeakMap[number]>; + __getModule__: InstanceEach[number]>( + ctor: C, + ) => InstanceType; __addModule__: >>( newModule: N, ) => Context<[...M, N], K, Pr, Po>; diff --git a/src/reactive.ts b/src/reactive.ts index a11d0fc..20d712c 100644 --- a/src/reactive.ts +++ b/src/reactive.ts @@ -6,6 +6,7 @@ export type Ref = { (newValue: T): void; subscribe(func: RefMatchingFunc, options?: { immediate?: boolean }): () => void; unsubscribe(func: RefMatchingFunc): void; + clear(): void; }; type RefOptions = { equals?: (newValue: T, oldValue: T) => boolean }; @@ -28,6 +29,7 @@ export function ref(initial: T, options?: RefOptions): Ref { if (ops?.immediate) callback(value, value); return () => result.unsubscribe(callback); }; + result.clear = subs.clear; result.unsubscribe = (callback) => subs.delete(callback); return result; } @@ -38,6 +40,7 @@ export type Hook = { (...args: Args): void; subscribe(callback: HookMatchingFunc): () => void; unsubscribe(callback: HookMatchingFunc): void; + clear(): void; }; export function hook(): Hook { @@ -50,6 +53,7 @@ export function hook(): Hook { return () => result.unsubscribe(callback); }; result.unsubscribe = (callback) => subs.delete(callback); + result.clear = subs.clear; return result; } @@ -60,6 +64,7 @@ export type Computed = { subscribe(func: RefMatchingFunc, options?: { immediate?: boolean }): () => void; unsubscribe(func: RefMatchingFunc): void; dispose(): void; + clear(): void; }; type ComputedOptions = { equals?: (newValue: T, oldValue: T) => boolean; @@ -103,5 +108,6 @@ export function computed(getter: () => T, options?: ComputedOptions): Comp result.dispose = () => { while (cleanup.length) cleanup.pop()!(); }; + result.clear = subs.clear; return result; } From 10275cee3f3d56b081abd8a7f448ac91a1a54eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?He=CC=84sperus?= Date: Wed, 1 Jul 2026 13:24:46 +0800 Subject: [PATCH 2/2] chore: update pnpm --- pnpm-lock.yaml | 76 +++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5da2774..1da8994 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,52 +7,52 @@ importers: configDependencies: {} packageManagerDependencies: '@pnpm/exe': - specifier: ^11.1.2 - version: 11.2.2 + specifier: 11.9.0 + version: 11.9.0 pnpm: - specifier: ^11.1.2 - version: 11.2.2 + specifier: 11.9.0 + version: 11.9.0 packages: - '@pnpm/exe@11.2.2': - resolution: {integrity: sha512-9AGho6f10GYF/XHvnpO6wnzDIAiHNSs2PyOTelrNNyUiHwfTVtnJoXwRz/6yPJAYOF3erhPauv5oxf62uh581w==} + '@pnpm/exe@11.9.0': + resolution: {integrity: sha512-pPPOpR79qW3nsNhlyDIdfstli4Bi78mk8r22ySxpFRwMbO8KXSjGrVzGmJBsVX39NnJTh7/WADj527nZhG9H9g==} hasBin: true - '@pnpm/linux-arm64@11.2.2': - resolution: {integrity: sha512-cMEqyEwpghHb1UggKuowTuGKvbWe1Ra6bK3SF9CWoIrz36mzQz3FXxYXx1Theo8lmkwWH2MZdUGHKgtUoqEGKg==} + '@pnpm/linux-arm64@11.9.0': + resolution: {integrity: sha512-XYmY2qadHauBA3QaHi2R7fI6kt5Flje0WHz9MVrbH0kVH/XLpfOLnwPeE1+EX6K/nDa2CBvzp35VjYCNGFJa9A==} cpu: [arm64] os: [linux] - '@pnpm/linux-x64@11.2.2': - resolution: {integrity: sha512-AShxDdan9wfAFbIGAO5YnbGRf3zuETOZVMuWqmx4mJLaAOR3kiA3Rwhzj3jyTsAoodn7Xdaxq9G1M3FpB92mkQ==} + '@pnpm/linux-x64@11.9.0': + resolution: {integrity: sha512-fl7W5imnSmmgXIqMQFZ/rPaVvk9OkKF8/anqHZE3XEDfWcn3BlWGndyOEas/JN7u2BXWYjs63DJZ3rnG6WOhLA==} cpu: [x64] os: [linux] - '@pnpm/linuxstatic-arm64@11.2.2': - resolution: {integrity: sha512-m7BCdqFdMFo3fkiOpcOLa70c3Ppy5OKv78HXSIfzL4ajHBdPQfmv03VgC3U08l1ST/EeQFuSt+Za0azmOJyYqA==} + '@pnpm/linuxstatic-arm64@11.9.0': + resolution: {integrity: sha512-fif8xbnzVEAIlvaU4yIgWKXeXYb4Kj6WMEl/KvM2x1Rp3AKAjBW/53SGzxO4cZP9doAqUzOIpMRGFVbHGeMDRw==} cpu: [arm64] os: [linux] libc: [musl] - '@pnpm/linuxstatic-x64@11.2.2': - resolution: {integrity: sha512-UABTQUhdn6eCx/IlGVrdwklKT00pTHrjLNXdviP4OReJa1trM5HDWcDnreIg89ghCFmee+UTBKDx1FYlLON8EQ==} + '@pnpm/linuxstatic-x64@11.9.0': + resolution: {integrity: sha512-9dKu3QdShqOpnWrjW9owARpIJeP0ul8UgIIbBUv8VDGEYibt+g49zQsNaD7SdMD3WeRSjExPQ1zIhplzr5cwvQ==} cpu: [x64] os: [linux] libc: [musl] - '@pnpm/macos-arm64@11.2.2': - resolution: {integrity: sha512-EakwHSWIxzza6fO6zQkmkUphoadjer9VXCsWRax1D4qNWmChKfn2muYFj6BOChS999lwb4fb42gc61Nbx0X6iw==} + '@pnpm/macos-arm64@11.9.0': + resolution: {integrity: sha512-MWzBTgeI5p3odjdVltYvFXaSWAjF2Xk5YaxiP/u2RmW8N6PHsLyIyj37Ds992CrXgFM8fO1RpvsEirozhsD6KA==} cpu: [arm64] os: [darwin] - '@pnpm/win-arm64@11.2.2': - resolution: {integrity: sha512-eXzlXAnwRAI9Uff1U2pfTJxC78vL8aGxU/fsUt/RzWjS09xMQZ2qtAunKg869fAi6xfsquDbogkdTZA3163lIw==} + '@pnpm/win-arm64@11.9.0': + resolution: {integrity: sha512-u/QxEcbKJZxC1t3zUYCZiHzu7TaZ/iXc6EGZoQjkeVT0LXmEVR6ypcK3ByjhIqbxQ3HGX75gnpIpR+VjRjubfw==} cpu: [arm64] os: [win32] - '@pnpm/win-x64@11.2.2': - resolution: {integrity: sha512-X74bQ4bvjSCYapcupRsGrse8cAg7XhPKXRn1o1qOouux1nJquz9lh2h5uKz8GPx816OUsYo9FS8DV3N9W+L8QA==} + '@pnpm/win-x64@11.9.0': + resolution: {integrity: sha512-HqJVHmZG5UKfLi38AjMl2azVmq87TlWRhwSW+f4q9LLaZeAkFyIZ7LY/pN6mh4VlH9yWj90C+tsb1yKiy7OKnw==} cpu: [x64] os: [win32] @@ -116,45 +116,45 @@ packages: resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==} engines: {node: '>=8'} - pnpm@11.2.2: - resolution: {integrity: sha512-NuZiH61QYXiTZFXnAke4gI707CV5ep9DepMoGgIEhOJgf2pGmiLpgph8PbuIZuMHFRSrEKShdJ4G7c0ewRhDbw==} + pnpm@11.9.0: + resolution: {integrity: sha512-vWgtXQP+Ul73yf1ngMaITR51asTJyf4AxTh4KCQxDc+Q493E9Tg18G3669UIXkGFXgvLs7YN4qxburieUDbwOw==} engines: {node: '>=22.13'} hasBin: true snapshots: - '@pnpm/exe@11.2.2': + '@pnpm/exe@11.9.0': dependencies: '@reflink/reflink': 0.1.19 detect-libc: 2.1.2 optionalDependencies: - '@pnpm/linux-arm64': 11.2.2 - '@pnpm/linux-x64': 11.2.2 - '@pnpm/linuxstatic-arm64': 11.2.2 - '@pnpm/linuxstatic-x64': 11.2.2 - '@pnpm/macos-arm64': 11.2.2 - '@pnpm/win-arm64': 11.2.2 - '@pnpm/win-x64': 11.2.2 + '@pnpm/linux-arm64': 11.9.0 + '@pnpm/linux-x64': 11.9.0 + '@pnpm/linuxstatic-arm64': 11.9.0 + '@pnpm/linuxstatic-x64': 11.9.0 + '@pnpm/macos-arm64': 11.9.0 + '@pnpm/win-arm64': 11.9.0 + '@pnpm/win-x64': 11.9.0 - '@pnpm/linux-arm64@11.2.2': + '@pnpm/linux-arm64@11.9.0': optional: true - '@pnpm/linux-x64@11.2.2': + '@pnpm/linux-x64@11.9.0': optional: true - '@pnpm/linuxstatic-arm64@11.2.2': + '@pnpm/linuxstatic-arm64@11.9.0': optional: true - '@pnpm/linuxstatic-x64@11.2.2': + '@pnpm/linuxstatic-x64@11.9.0': optional: true - '@pnpm/macos-arm64@11.2.2': + '@pnpm/macos-arm64@11.9.0': optional: true - '@pnpm/win-arm64@11.2.2': + '@pnpm/win-arm64@11.9.0': optional: true - '@pnpm/win-x64@11.2.2': + '@pnpm/win-x64@11.9.0': optional: true '@reflink/reflink-darwin-arm64@0.1.19': @@ -194,7 +194,7 @@ snapshots: detect-libc@2.1.2: {} - pnpm@11.2.2: {} + pnpm@11.9.0: {} --- lockfileVersion: '9.0'