MCPcopy Create free account
hub / github.com/GCWing/BitFun / GitStateManager

Class GitStateManager

src/web-ui/src/tools/git/state/GitStateManager.ts:60–809  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60export class GitStateManager {
61 private static instance: GitStateManager;
62
63 private states = new Map<string, GitState>();
64 private subscribers = new Map<string, Set<SubscriberEntry>>();
65 private windowFocusRefreshCounts = new Map<string, number>();
66 private refreshDebounceTimers = new Map<string, ReturnType<typeof setTimeout>>();
67 private refreshLocks = new Map<string, Promise<void>>();
68 private pendingRefreshes = new Map<string, PendingRefresh>();
69 private cacheConfig: CacheConfig = { ...DEFAULT_CACHE_CONFIG };
70 private readonly DEBOUNCE_DELAY = 100;
71 private globalListenersInitialized = false;
72
73 private constructor() {
74 this.setupGlobalListeners();
75 }
76
77 static getInstance(): GitStateManager {
78 if (!GitStateManager.instance) {
79 GitStateManager.instance = new GitStateManager();
80 }
81 return GitStateManager.instance;
82 }
83
84 /**
85 * Reset instance (for testing only)
86 */
87 static resetInstance(): void {
88 if (GitStateManager.instance) {
89 GitStateManager.instance.dispose();
90 GitStateManager.instance = undefined as any;
91 }
92 }
93
94 /**
95 * Subscribe to repository state changes.
96 * @returns Unsubscribe function.
97 */
98 subscribe(
99 repositoryPath: string,
100 callback: GitStateSubscriber,
101 options: SubscribeOptions = {}
102 ): () => void {
103 const normalizedPath = this.normalizePath(repositoryPath);
104
105 if (!this.subscribers.has(normalizedPath)) {
106 this.subscribers.set(normalizedPath, new Set());
107 }
108
109 const entry: SubscriberEntry = { callback, options };
110 this.subscribers.get(normalizedPath)!.add(entry);
111
112 if (options.immediate !== false) {
113 const currentState = this.states.get(normalizedPath);
114 if (currentState) {
115 callback(currentState, null, ['basic', 'status', 'detailed']);
116 }
117 }

Callers

nothing calls this directly

Calls 5

refreshMethod · 0.95
invalidateCacheMethod · 0.95
sendDebugProbeFunction · 0.90
includesMethod · 0.80
fromMethod · 0.45

Tested by

no test coverage detected