MCPcopy
hub / github.com/mathuo/dockview / ModuleRegistry

Class ModuleRegistry

packages/dockview-core/src/dockview/modules.ts:131–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131export class ModuleRegistry<THost> implements IDisposable {
132 private readonly _modules = new Map<string, DockviewModule<any>>();
133 private readonly _services: ServiceCollection = {};
134 private readonly _initDisposables: IDisposable[] = [];
135
136 get services(): ServiceCollection {
137 return this._services;
138 }
139
140 register<H>(module: DockviewModule<H>): void {
141 if (this._modules.has(module.moduleName)) {
142 return;
143 }
144 if (module.dependsOn) {
145 for (const dep of module.dependsOn) {
146 this.register(dep);
147 }
148 }
149 this._modules.set(module.moduleName, module);
150 }
151
152 initialize(host: THost): void {
153 for (const module of this._modules.values()) {
154 if (!module.services) {
155 continue;
156 }
157 for (const [name, factory] of Object.entries(module.services)) {
158 (this._services as Record<string, unknown>)[name] = (
159 factory as (h: THost) => unknown
160 )(host);
161 }
162 }
163 }
164
165 postConstruct(host: THost): void {
166 for (const module of this._modules.values()) {
167 if (module.init) {
168 this._initDisposables.push(
169 (
170 module.init as (
171 h: THost,
172 s: ServiceCollection
173 ) => IDisposable
174 )(host, this._services)
175 );
176 }
177 }
178 }
179
180 has(moduleName: string): boolean {
181 return this._modules.has(moduleName);
182 }
183
184 dispose(): void {
185 // Tear down init() subscriptions first so they stop firing into
186 // services that are about to be disposed.
187 for (const disposable of this._initDisposables) {
188 disposable.dispose();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…