Skip to content

Commit e9521da

Browse files
committed
explicitly register all watchers
1 parent b0c8bbe commit e9521da

11 files changed

Lines changed: 35 additions & 34 deletions

File tree

src/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
import {Watcher} from "./watchers/watcher";
2+
3+
import system from "./watchers/system";
4+
import html from "./watchers/html";
5+
import svg from "./watchers/svg";
6+
import canvas from "./watchers/canvas";
7+
import ui from "./watchers/ui";
8+
import compiler from "./watchers/compiler";
9+
import shape from "./watchers/shape";
10+
import editor from "./watchers/editor";
11+
import tagBrowser from "./watchers/tag-browser";
12+
13+
Watcher.register("system", system);
14+
Watcher.register("html", html);
15+
Watcher.register("svg", svg);
16+
Watcher.register("canvas", canvas);
17+
Watcher.register("ui", ui);
18+
Watcher.register("compiler", compiler);
19+
Watcher.register("shape", shape);
20+
Watcher.register("editor", editor);
21+
Watcher.register("tag browser", tagBrowser);
22+
123
export {Watcher, Program, appendAsEAVs, RawEAV, createId} from "./watchers/watcher";
224

325
export var watcherPath = "./build/src/watchers";

src/runtime/dsl2.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,9 +1751,6 @@ export class Program {
17511751
}
17521752

17531753
attach(id:string) {
1754-
try {
1755-
require(`../watchers/${id}.js`); // allow webpack to find watcher modules
1756-
} catch (e) { }
17571754
let WatcherConstructor = Watcher.get(id);
17581755
if(!WatcherConstructor) throw new Error(`Unable to attach unknown watcher '${id}'.`);
17591756
if(this.watchers[id]) return this.watchers[id];

src/watchers/canvas.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Watcher, RawMap, RawValue, RawEAV, RawEAVC, maybeIntern} from "./watcher";
2-
import {HTMLWatcher} from "./html";
2+
import HTMLWatcher from "./html";
33
import {v4 as uuid} from "node-uuid";
44

55
function asValue(value:RawValue) {
@@ -40,7 +40,7 @@ export interface Operation {type: OperationType, args:any, paths:RawValue[]};
4040
// {fillStyle: "#000000", strokeStyle: "#000000", lineWidth: 1, lineCap: "butt", lineJoin: "miter"}
4141
export interface PathStyle {[key:string]: RawValue|undefined, fillStyle?:string, strokeStyle?:string, lineWidth?:number, lineCap?:string, lineJoin?: string };
4242

43-
class CanvasWatcher extends Watcher {
43+
export default class CanvasWatcher extends Watcher {
4444
html:HTMLWatcher;
4545
canvases:RawMap<RawValue[]|undefined> = {};
4646
paths:RawMap<RawValue[]|undefined> = {};
@@ -393,8 +393,6 @@ class CanvasWatcher extends Watcher {
393393
}
394394
}
395395

396-
Watcher.register("canvas", CanvasWatcher);
397-
398396
/*
399397
* [#canvas/root width height children:
400398
* [#canvas/rect x y width height fill? stroke?]]

src/watchers/compiler.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface CompilationContext {
1111
variables: {[id:string]: Reference},
1212
}
1313

14-
export class CompilerWatcher extends Watcher {
14+
export default class CompilerWatcher extends Watcher {
1515

1616
blocksToCompile:{[blockID:string]: boolean} = {};
1717
blocksToRemove:{[blockID:string]: boolean} = {};
@@ -461,5 +461,3 @@ export class CompilerWatcher extends Watcher {
461461

462462
}
463463
}
464-
465-
Watcher.register("compiler", CompilerWatcher);

src/watchers/editor.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//--------------------------------------------------------------------
44

55
import {Watcher, Program, RawMap, RawValue, RawEAV, forwardDiffs, appendAsEAVs, createId} from "../watchers/watcher";
6-
import {CompilerWatcher} from "../watchers/compiler";
6+
import CompilerWatcher from "../watchers/compiler";
77

8-
class EditorWatcher extends Watcher {
8+
export default class EditorWatcher extends Watcher {
99
editor: Program;
1010
setup() {
1111
this.editor = this.createEditor();
@@ -1350,5 +1350,3 @@ class EditorWatcher extends Watcher {
13501350
})
13511351
}
13521352
}
1353-
1354-
Watcher.register("editor", EditorWatcher);

src/watchers/html.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {v4 as uuid} from "node-uuid";
55

66
export interface Instance extends HTMLElement {__element?: RawValue, __styles?: RawValue[], __sort?: RawValue, listeners?: {[event: string]: boolean}}
77

8-
export class HTMLWatcher extends DOMWatcher<Instance> {
8+
export default class HTMLWatcher extends DOMWatcher<Instance> {
99
tagPrefix = "html";
1010

1111
addExternalRoot(tag:string, element:HTMLElement) {
@@ -326,5 +326,3 @@ export class HTMLWatcher extends DOMWatcher<Instance> {
326326
.asObjects<{listener:string, elemId:ID, instanceId:RawValue}>((diffs) => this.exportListeners(diffs));
327327
}
328328
}
329-
330-
Watcher.register("html", HTMLWatcher);

src/watchers/shape.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Watcher, RawValue, RawEAV, RawEAVC} from "./watcher";
22

3-
class ShapeWatcher extends Watcher {
3+
export default class ShapeWatcher extends Watcher {
44
setup() {
55
this.program.attach("html");
66
this.program.attach("canvas");
@@ -210,5 +210,3 @@ class ShapeWatcher extends Watcher {
210210
})
211211
}
212212
}
213-
214-
Watcher.register("shape", ShapeWatcher);

src/watchers/svg.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import {Watcher, RawValue, RawEAV, RawEAVC} from "./watcher";
22
import {DOMWatcher, ElemInstance} from "./dom";
33

4-
interface Instance extends SVGElement {__element?: RawValue, __styles?: RawValue[], __sort?: RawValue}
4+
export interface Instance extends SVGElement {__element?: RawValue, __styles?: RawValue[], __sort?: RawValue}
55

6-
7-
class SVGWatcher extends DOMWatcher<Instance> {
6+
export default class SVGWatcher extends DOMWatcher<Instance> {
87
tagPrefix = "svg";
98

109
createInstance(id:RawValue, element:RawValue, tagname:RawValue):Instance {
@@ -36,5 +35,3 @@ class SVGWatcher extends DOMWatcher<Instance> {
3635
super.setup();
3736
}
3837
}
39-
40-
Watcher.register("svg", SVGWatcher);

src/watchers/system.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Watcher} from "./watcher";
22
import {ID} from "../runtime/runtime";
33

4-
class SystemWatcher extends Watcher {
4+
export default class SystemWatcher extends Watcher {
55
timers:{[key:string]: {timer:any, prev:Date|undefined, frame:number}} = {};
66

77
getTime(changes:any[], timer:ID, frame:number, date?:Date) {
@@ -50,5 +50,3 @@ class SystemWatcher extends Watcher {
5050
})
5151
}
5252
}
53-
54-
Watcher.register("system", SystemWatcher);

src/watchers/tag-browser.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Watcher, Program, RawMap, RawValue, RawEAVC} from "./watcher";
22
import {v4 as uuid} from "node-uuid";
33

4-
import {UIWatcher} from "../watchers/ui";
4+
import UIWatcher from "../watchers/ui";
55

66
interface Attrs extends RawMap<RawValue> {}
77

@@ -19,7 +19,7 @@ function collapse<T extends any[]>(...args:T[]):T {
1919
return all;
2020
}
2121

22-
export class TagBrowserWatcher extends Watcher {
22+
export default class TagBrowserWatcher extends Watcher {
2323
browser:Program = this.createTagBrowser();
2424

2525
setup() {
@@ -322,4 +322,3 @@ export class TagBrowserWatcher extends Watcher {
322322
}
323323
}
324324

325-
Watcher.register("tag browser", TagBrowserWatcher);

0 commit comments

Comments
 (0)