返回 DeepSeek-Reasonix
useDockViewRequests.ts
根目录 / desktop / frontend / src / app-shell / useDockViewRequests.ts
1 import { useLayoutEffect, useState, useSyncExternalStore } from "react";
2 import { DockNavigation, type DockRequests } from "./dockNavigation";
3
4 export function useDockViewRequests(scope: string, view: string | null, incoming: DockRequests, owner?: DockNavigation, openViews?: readonly string[]): DockRequests {
5 const [local] = useState(() => new DockNavigation());
6 const navigation = owner ?? local;
7 const snapshot = useSyncExternalStore(navigation.subscribe, navigation.getSnapshot, navigation.getSnapshot);
8 useLayoutEffect(() => { navigation.commit(scope, view, incoming, openViews); });
9 useLayoutEffect(() => owner ? undefined : local.attach(), [local, owner]);
10 return view && navigation.matches(scope, view) ? snapshot : navigation.restoredView(scope, view);
11 }
12
12 lines TYPESCRIPT