Skip to content

Commit f07b737

Browse files
committed
clean up MessageRouter
1 parent cad39a3 commit f07b737

File tree

2 files changed

+1
-53
lines changed

2 files changed

+1
-53
lines changed

packages/shadow-ents/src/constants.ts

-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ export const VoidToken = '#void';
2626
*/
2727
export const ContextLost = 'contextLost';
2828

29-
export const Init = 'init'; // TODO remove 'init' event
3029
export const Configure = 'configure';
3130
export const ChangeTrail = 'changeTrail';
3231
export const Destroy = 'destroy';
3332

3433
export const Loaded = 'loaded';
35-
export const Ready = 'ready'; // TODO remove 'ready' event
3634
export const AppliedChangeTrail = 'appliedChangeTrail';
3735
export const ImportedModule = 'importedModule';
3836
export const Destroyed = 'destroyed';

packages/shadow-ents/src/worker/MessageRouter.ts

+1-51
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,14 @@ import {
55
Destroy,
66
Destroyed,
77
ImportedModule,
8-
Init,
98
MessageToView,
10-
Ready,
119
ShadowObjectsExport,
1210
} from '../constants.js';
1311
import {Kernel, type MessageToViewEvent} from '../entities/Kernel.js';
14-
import {shadowObjects} from '../entities/ShadowObject.js';
1512
import {importModule} from '../entities/importModule.js';
16-
import type {
17-
AppliedChangeTrailEvent,
18-
ImportedModuleEvent,
19-
ShadowObjectConstructor,
20-
ShadowObjectsModule,
21-
SyncEvent,
22-
} from '../types.js';
13+
import type {AppliedChangeTrailEvent, ImportedModuleEvent, ShadowObjectsModule, SyncEvent} from '../types.js';
2314
import {toUrlString} from '../utils/toUrlString.js';
2415

25-
// TODO(cleanup) remove InitPayloadData
26-
interface InitPayloadData {
27-
importSrc?: string;
28-
}
29-
3016
interface ConfigurePayloadData {
3117
importModule?: string;
3218
}
@@ -53,11 +39,6 @@ export class MessageRouter {
5339

5440
route(event: MessageEvent) {
5541
switch (event.data.type) {
56-
case Init:
57-
// TODO(cleanup) remove Init event
58-
this.#onInit(event.data);
59-
break;
60-
6142
case Configure:
6243
this.#configure(event.data);
6344
break;
@@ -114,41 +95,10 @@ export class MessageRouter {
11495
}
11596
}
11697

117-
// TODO(cleanup) remove onInit
118-
#onInit(data: InitPayloadData) {
119-
// console.debug('[MessageRouter] on init', data);
120-
121-
if ('importSrc' in data) {
122-
this.#loadScript(data.importSrc);
123-
} else {
124-
console.error('[MessageRouter] missing importSrc property!');
125-
}
126-
}
127-
12898
#onDestroy(data: any) {
12999
console.debug('[MessageRouter] on destroy', data);
130100
this.kernel.off(this);
131101
this.#importedModules.clear();
132102
this.postMessage({type: Destroyed});
133103
}
134-
135-
// TODO(cleanup) remove loadScript
136-
async #loadScript(src: string) {
137-
const mod = await import(/* @vite-ignore */ src);
138-
139-
// console.debug('[MessageRouter] imported', vfxMod);
140-
141-
if (typeof mod.onload === 'function') {
142-
mod.onload({
143-
shadowObjects: {
144-
define: (token: string, constructor: ShadowObjectConstructor) =>
145-
shadowObjects.define(token, constructor, this.kernel.registry),
146-
},
147-
kernel: this.kernel,
148-
registry: this.kernel.registry,
149-
});
150-
}
151-
152-
this.postMessage({type: Ready});
153-
}
154104
}

0 commit comments

Comments
 (0)