๐ src/downloader/adapters/react.ts
D-OPEN SOVEREIGN
Documentation & Insights
Reactive LRU auto-cleanup state.
Usage:
const { active, freedBytes, removedCount } = usePruning()1/*
2 * Copyright (c) 2026 DataPond D-Library Pty Ltd. ("The Sanctuary")
3 * Non-Profit Public Library โ The World Library
4 *
5 * D-SAFE Certification issued by POND Enterprise.
6 * Published under the D-Open Code Sovereign Licence v1.0 framework
7 * DataPond D-Library All exclusive Right reserved on modifiying the code - CC Attribution to data pond, Non modifiable, Non Commercial.
8 * https://registry.world.bibliotech.com/licence
9 * Source code donated to DataPond D-Library by it's author: data pond.
10 *
11 * Technical Guardian ("The Shield"): Pond Enterprise Pty Ltd. (ACN 694 747 987)
12 * All liability claims about D-SAFE certification issues coming from the published D-Safe direction must be addressed with Pond Enterprise Pty Ltd.
13 * Code Modification automatically voids the certified liability protection provided by Pond Enterprise.
14 */
15// React 18 adapter โ uses useSyncExternalStore for tear-free reads (ยง5.6.4).
16import { useSyncExternalStore } from 'react';
17import { downloadState } from '../state';
18
19let version = 0;
20downloadState.subscribe(() => version++);
21
22const useTick = () =>
23 useSyncExternalStore(downloadState.subscribe, () => version);
24
25export const useFileStatus = (txId: string) => { useTick(); return downloadState.get(txId); };
26export const useRenderStatus = (txId: string) => { useTick(); return downloadState.getRender(txId); };
27export const useGlobalProgress = () => { useTick(); return downloadState.summary(); };
28
29/**
30 * Reactive LRU auto-cleanup state.
31 *
32 * Usage:
33 * const { active, freedBytes, removedCount } = usePruning()
34 */
35export const usePruning = () => { useTick(); return downloadState.pruning; };
36