From 56477f886e2b46e3f28e32b47300a68ddc31fdb9 Mon Sep 17 00:00:00 2001 From: Alexey Shamrin Date: Thu, 20 Apr 2017 16:49:45 +0300 Subject: [PATCH 1/4] allow webpack to find common watchers --- src/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/index.ts b/src/index.ts index 2dd5f25ac..67495b9b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,10 @@ export {Watcher, Program, appendAsEAVs, RawEAV, createId} from "./watchers/watcher"; +// allow bundlers (e.g. webpack) to find common watcher modules +import './watchers/system'; +import './watchers/html'; +import './watchers/svg'; +import './watchers/canvas'; +import './watchers/ui'; + export var watcherPath = "./build/src/watchers"; From b183cd75f1308d9f1de99ae50f513f2ecf5820ed Mon Sep 17 00:00:00 2001 From: Alexey Shamrin Date: Thu, 20 Apr 2017 19:15:34 +0300 Subject: [PATCH 2/4] more robust webpack fix --- src/index.ts | 7 ------- src/runtime/dsl2.ts | 3 +++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 67495b9b9..2dd5f25ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,3 @@ export {Watcher, Program, appendAsEAVs, RawEAV, createId} from "./watchers/watcher"; -// allow bundlers (e.g. webpack) to find common watcher modules -import './watchers/system'; -import './watchers/html'; -import './watchers/svg'; -import './watchers/canvas'; -import './watchers/ui'; - export var watcherPath = "./build/src/watchers"; diff --git a/src/runtime/dsl2.ts b/src/runtime/dsl2.ts index b41bc0fbd..8b71cf0e5 100644 --- a/src/runtime/dsl2.ts +++ b/src/runtime/dsl2.ts @@ -1751,6 +1751,9 @@ export class Program { } attach(id:string) { + try { + require(`../watchers/${id}.js`); // allow webpack to find watcher modules + } catch (e) { } let WatcherConstructor = Watcher.get(id); if(!WatcherConstructor) throw new Error(`Unable to attach unknown watcher '${id}'.`); if(this.watchers[id]) return this.watchers[id]; From f3f5565c1d806a8876aa2d2b340524f102d14754 Mon Sep 17 00:00:00 2001 From: Alexey Shamrin Date: Fri, 21 Apr 2017 03:49:12 +0300 Subject: [PATCH 3/4] explicitly register all watchers --- src/index.ts | 22 ++++++++++++++++++++++ src/runtime/dsl2.ts | 3 --- src/watchers/canvas.ts | 6 ++---- src/watchers/compiler.ts | 4 +--- src/watchers/editor.ts | 6 ++---- src/watchers/html.ts | 4 +--- src/watchers/shape.ts | 4 +--- src/watchers/svg.ts | 7 ++----- src/watchers/system.ts | 4 +--- src/watchers/tag-browser.ts | 5 ++--- src/watchers/ui.ts | 4 +--- 11 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2dd5f25ac..8763e4285 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,25 @@ +import {Watcher} from "./watchers/watcher"; + +import system from "./watchers/system"; +import html from "./watchers/html"; +import svg from "./watchers/svg"; +import canvas from "./watchers/canvas"; +import ui from "./watchers/ui"; +import compiler from "./watchers/compiler"; +import shape from "./watchers/shape"; +import editor from "./watchers/editor"; +import tagBrowser from "./watchers/tag-browser"; + +Watcher.register("system", system); +Watcher.register("html", html); +Watcher.register("svg", svg); +Watcher.register("canvas", canvas); +Watcher.register("ui", ui); +Watcher.register("compiler", compiler); +Watcher.register("shape", shape); +Watcher.register("editor", editor); +Watcher.register("tag browser", tagBrowser); + export {Watcher, Program, appendAsEAVs, RawEAV, createId} from "./watchers/watcher"; export var watcherPath = "./build/src/watchers"; diff --git a/src/runtime/dsl2.ts b/src/runtime/dsl2.ts index 8b71cf0e5..b41bc0fbd 100644 --- a/src/runtime/dsl2.ts +++ b/src/runtime/dsl2.ts @@ -1751,9 +1751,6 @@ export class Program { } attach(id:string) { - try { - require(`../watchers/${id}.js`); // allow webpack to find watcher modules - } catch (e) { } let WatcherConstructor = Watcher.get(id); if(!WatcherConstructor) throw new Error(`Unable to attach unknown watcher '${id}'.`); if(this.watchers[id]) return this.watchers[id]; diff --git a/src/watchers/canvas.ts b/src/watchers/canvas.ts index d2c6a6e3e..caadd92c7 100644 --- a/src/watchers/canvas.ts +++ b/src/watchers/canvas.ts @@ -1,5 +1,5 @@ import {Watcher, RawMap, RawValue, RawEAV, RawEAVC, maybeIntern} from "./watcher"; -import {HTMLWatcher} from "./html"; +import HTMLWatcher from "./html"; import {v4 as uuid} from "uuid"; function asValue(value:RawValue) { @@ -40,7 +40,7 @@ export interface Operation {type: OperationType, args:any, paths:RawValue[]}; // {fillStyle: "#000000", strokeStyle: "#000000", lineWidth: 1, lineCap: "butt", lineJoin: "miter"} export interface PathStyle {[key:string]: RawValue|undefined, fillStyle?:string, strokeStyle?:string, lineWidth?:number, lineCap?:string, lineJoin?: string }; -class CanvasWatcher extends Watcher { +export default class CanvasWatcher extends Watcher { html:HTMLWatcher; canvases:RawMap = {}; paths:RawMap = {}; @@ -393,8 +393,6 @@ class CanvasWatcher extends Watcher { } } -Watcher.register("canvas", CanvasWatcher); - /* * [#canvas/root width height children: * [#canvas/rect x y width height fill? stroke?]] diff --git a/src/watchers/compiler.ts b/src/watchers/compiler.ts index b30fb2438..7cb9ab141 100644 --- a/src/watchers/compiler.ts +++ b/src/watchers/compiler.ts @@ -11,7 +11,7 @@ export interface CompilationContext { variables: {[id:string]: Reference}, } -export class CompilerWatcher extends Watcher { +export default class CompilerWatcher extends Watcher { blocksToCompile:{[blockID:string]: boolean} = {}; blocksToRemove:{[blockID:string]: boolean} = {}; @@ -461,5 +461,3 @@ export class CompilerWatcher extends Watcher { } } - -Watcher.register("compiler", CompilerWatcher); diff --git a/src/watchers/editor.ts b/src/watchers/editor.ts index bdf3195e8..de45a22d5 100644 --- a/src/watchers/editor.ts +++ b/src/watchers/editor.ts @@ -3,9 +3,9 @@ //-------------------------------------------------------------------- import {Watcher, Program, RawMap, RawValue, RawEAV, forwardDiffs, appendAsEAVs, createId} from "../watchers/watcher"; -import {CompilerWatcher} from "../watchers/compiler"; +import CompilerWatcher from "../watchers/compiler"; -class EditorWatcher extends Watcher { +export default class EditorWatcher extends Watcher { editor: Program; setup() { this.editor = this.createEditor(); @@ -1350,5 +1350,3 @@ class EditorWatcher extends Watcher { }) } } - -Watcher.register("editor", EditorWatcher); diff --git a/src/watchers/html.ts b/src/watchers/html.ts index 6979b18ca..4bae5d22a 100644 --- a/src/watchers/html.ts +++ b/src/watchers/html.ts @@ -5,7 +5,7 @@ import {v4 as uuid} from "uuid"; export interface Instance extends HTMLElement {__element?: RawValue, __styles?: RawValue[], __sort?: RawValue, listeners?: {[event: string]: boolean}} -export class HTMLWatcher extends DOMWatcher { +export default class HTMLWatcher extends DOMWatcher { tagPrefix = "html"; addExternalRoot(tag:string, element:HTMLElement) { @@ -326,5 +326,3 @@ export class HTMLWatcher extends DOMWatcher { .asObjects<{listener:string, elemId:ID, instanceId:RawValue}>((diffs) => this.exportListeners(diffs)); } } - -Watcher.register("html", HTMLWatcher); diff --git a/src/watchers/shape.ts b/src/watchers/shape.ts index 1768960ef..4f0b54470 100644 --- a/src/watchers/shape.ts +++ b/src/watchers/shape.ts @@ -1,6 +1,6 @@ import {Watcher, RawValue, RawEAV, RawEAVC} from "./watcher"; -class ShapeWatcher extends Watcher { +export default class ShapeWatcher extends Watcher { setup() { this.program.attach("html"); this.program.attach("canvas"); @@ -210,5 +210,3 @@ class ShapeWatcher extends Watcher { }) } } - -Watcher.register("shape", ShapeWatcher); diff --git a/src/watchers/svg.ts b/src/watchers/svg.ts index 6d3f55e0f..5a71d82f7 100644 --- a/src/watchers/svg.ts +++ b/src/watchers/svg.ts @@ -1,10 +1,9 @@ import {Watcher, RawValue, RawEAV, RawEAVC} from "./watcher"; import {DOMWatcher, ElemInstance} from "./dom"; -interface Instance extends SVGElement {__element?: RawValue, __styles?: RawValue[], __sort?: RawValue} +export interface Instance extends SVGElement {__element?: RawValue, __styles?: RawValue[], __sort?: RawValue} - -class SVGWatcher extends DOMWatcher { +export default class SVGWatcher extends DOMWatcher { tagPrefix = "svg"; createInstance(id:RawValue, element:RawValue, tagname:RawValue):Instance { @@ -36,5 +35,3 @@ class SVGWatcher extends DOMWatcher { super.setup(); } } - -Watcher.register("svg", SVGWatcher); diff --git a/src/watchers/system.ts b/src/watchers/system.ts index 1630ecd2a..ec4aff1cb 100644 --- a/src/watchers/system.ts +++ b/src/watchers/system.ts @@ -1,7 +1,7 @@ import {Watcher} from "./watcher"; import {ID} from "../runtime/runtime"; -class SystemWatcher extends Watcher { +export default class SystemWatcher extends Watcher { timers:{[key:string]: {timer:any, prev:Date|undefined, frame:number}} = {}; getTime(changes:any[], timer:ID, frame:number, date?:Date) { @@ -50,5 +50,3 @@ class SystemWatcher extends Watcher { }) } } - -Watcher.register("system", SystemWatcher); diff --git a/src/watchers/tag-browser.ts b/src/watchers/tag-browser.ts index bb0b325c7..c66b6d914 100644 --- a/src/watchers/tag-browser.ts +++ b/src/watchers/tag-browser.ts @@ -1,7 +1,7 @@ import {Watcher, Program, RawMap, RawValue, RawEAVC} from "./watcher"; import {v4 as uuid} from "uuid"; -import {UIWatcher} from "../watchers/ui"; +import UIWatcher from "../watchers/ui"; interface Attrs extends RawMap {} @@ -19,7 +19,7 @@ function collapse(...args:T[]):T { return all; } -export class TagBrowserWatcher extends Watcher { +export default class TagBrowserWatcher extends Watcher { browser:Program = this.createTagBrowser(); setup() { @@ -322,4 +322,3 @@ export class TagBrowserWatcher extends Watcher { } } -Watcher.register("tag browser", TagBrowserWatcher); diff --git a/src/watchers/ui.ts b/src/watchers/ui.ts index 657379770..75b6fc7a6 100644 --- a/src/watchers/ui.ts +++ b/src/watchers/ui.ts @@ -3,7 +3,7 @@ import {v4 as uuid} from "uuid"; export interface Attrs extends RawMap {} -export class UIWatcher extends Watcher { +export default class UIWatcher extends Watcher { protected static _addAttrs(id:string, attrs?: Attrs, eavs:RawEAV[] = []) { if(attrs) { for(let attr in attrs) { @@ -516,5 +516,3 @@ export class UIWatcher extends Watcher { } } - -Watcher.register("ui", UIWatcher); From 6305ce45195e4c4f5f930dfa46849e92e4cc4857 Mon Sep 17 00:00:00 2001 From: Alexey Shamrin Date: Fri, 21 Apr 2017 04:16:09 +0300 Subject: [PATCH 4/4] simplify changes --- src/index.ts | 30 +++++++++--------------------- src/watchers/canvas.ts | 6 ++++-- src/watchers/compiler.ts | 4 +++- src/watchers/editor.ts | 6 ++++-- src/watchers/html.ts | 4 +++- src/watchers/shape.ts | 4 +++- src/watchers/svg.ts | 4 +++- src/watchers/system.ts | 4 +++- src/watchers/tag-browser.ts | 5 +++-- src/watchers/ui.ts | 4 +++- 10 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8763e4285..88570c2de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,24 +1,12 @@ -import {Watcher} from "./watchers/watcher"; - -import system from "./watchers/system"; -import html from "./watchers/html"; -import svg from "./watchers/svg"; -import canvas from "./watchers/canvas"; -import ui from "./watchers/ui"; -import compiler from "./watchers/compiler"; -import shape from "./watchers/shape"; -import editor from "./watchers/editor"; -import tagBrowser from "./watchers/tag-browser"; - -Watcher.register("system", system); -Watcher.register("html", html); -Watcher.register("svg", svg); -Watcher.register("canvas", canvas); -Watcher.register("ui", ui); -Watcher.register("compiler", compiler); -Watcher.register("shape", shape); -Watcher.register("editor", editor); -Watcher.register("tag browser", tagBrowser); +export {SystemWatcher} from "./watchers/system"; +export {HTMLWatcher} from "./watchers/html"; +export {SVGWatcher} from "./watchers/svg"; +export {CanvasWatcher} from "./watchers/canvas"; +export {UIWatcher} from "./watchers/ui"; +export {CompilerWatcher} from "./watchers/compiler"; +export {ShapeWatcher} from "./watchers/shape"; +export {EditorWatcher} from "./watchers/editor"; +export {TagBrowserWatcher} from "./watchers/tag-browser"; export {Watcher, Program, appendAsEAVs, RawEAV, createId} from "./watchers/watcher"; diff --git a/src/watchers/canvas.ts b/src/watchers/canvas.ts index caadd92c7..d6d81ab9e 100644 --- a/src/watchers/canvas.ts +++ b/src/watchers/canvas.ts @@ -1,5 +1,5 @@ import {Watcher, RawMap, RawValue, RawEAV, RawEAVC, maybeIntern} from "./watcher"; -import HTMLWatcher from "./html"; +import {HTMLWatcher} from "./html"; import {v4 as uuid} from "uuid"; function asValue(value:RawValue) { @@ -40,7 +40,7 @@ export interface Operation {type: OperationType, args:any, paths:RawValue[]}; // {fillStyle: "#000000", strokeStyle: "#000000", lineWidth: 1, lineCap: "butt", lineJoin: "miter"} export interface PathStyle {[key:string]: RawValue|undefined, fillStyle?:string, strokeStyle?:string, lineWidth?:number, lineCap?:string, lineJoin?: string }; -export default class CanvasWatcher extends Watcher { +export class CanvasWatcher extends Watcher { html:HTMLWatcher; canvases:RawMap = {}; paths:RawMap = {}; @@ -397,3 +397,5 @@ export default class CanvasWatcher extends Watcher { * [#canvas/root width height children: * [#canvas/rect x y width height fill? stroke?]] */ + +Watcher.register("canvas", CanvasWatcher); diff --git a/src/watchers/compiler.ts b/src/watchers/compiler.ts index 7cb9ab141..b30fb2438 100644 --- a/src/watchers/compiler.ts +++ b/src/watchers/compiler.ts @@ -11,7 +11,7 @@ export interface CompilationContext { variables: {[id:string]: Reference}, } -export default class CompilerWatcher extends Watcher { +export class CompilerWatcher extends Watcher { blocksToCompile:{[blockID:string]: boolean} = {}; blocksToRemove:{[blockID:string]: boolean} = {}; @@ -461,3 +461,5 @@ export default class CompilerWatcher extends Watcher { } } + +Watcher.register("compiler", CompilerWatcher); diff --git a/src/watchers/editor.ts b/src/watchers/editor.ts index de45a22d5..7c17106ba 100644 --- a/src/watchers/editor.ts +++ b/src/watchers/editor.ts @@ -3,9 +3,9 @@ //-------------------------------------------------------------------- import {Watcher, Program, RawMap, RawValue, RawEAV, forwardDiffs, appendAsEAVs, createId} from "../watchers/watcher"; -import CompilerWatcher from "../watchers/compiler"; +import {CompilerWatcher} from "../watchers/compiler"; -export default class EditorWatcher extends Watcher { +export class EditorWatcher extends Watcher { editor: Program; setup() { this.editor = this.createEditor(); @@ -1350,3 +1350,5 @@ export default class EditorWatcher extends Watcher { }) } } + +Watcher.register("editor", EditorWatcher); diff --git a/src/watchers/html.ts b/src/watchers/html.ts index 4bae5d22a..6979b18ca 100644 --- a/src/watchers/html.ts +++ b/src/watchers/html.ts @@ -5,7 +5,7 @@ import {v4 as uuid} from "uuid"; export interface Instance extends HTMLElement {__element?: RawValue, __styles?: RawValue[], __sort?: RawValue, listeners?: {[event: string]: boolean}} -export default class HTMLWatcher extends DOMWatcher { +export class HTMLWatcher extends DOMWatcher { tagPrefix = "html"; addExternalRoot(tag:string, element:HTMLElement) { @@ -326,3 +326,5 @@ export default class HTMLWatcher extends DOMWatcher { .asObjects<{listener:string, elemId:ID, instanceId:RawValue}>((diffs) => this.exportListeners(diffs)); } } + +Watcher.register("html", HTMLWatcher); diff --git a/src/watchers/shape.ts b/src/watchers/shape.ts index 4f0b54470..d166a13a0 100644 --- a/src/watchers/shape.ts +++ b/src/watchers/shape.ts @@ -1,6 +1,6 @@ import {Watcher, RawValue, RawEAV, RawEAVC} from "./watcher"; -export default class ShapeWatcher extends Watcher { +export class ShapeWatcher extends Watcher { setup() { this.program.attach("html"); this.program.attach("canvas"); @@ -210,3 +210,5 @@ export default class ShapeWatcher extends Watcher { }) } } + +Watcher.register("shape", ShapeWatcher); diff --git a/src/watchers/svg.ts b/src/watchers/svg.ts index 5a71d82f7..8d22c2caf 100644 --- a/src/watchers/svg.ts +++ b/src/watchers/svg.ts @@ -3,7 +3,7 @@ import {DOMWatcher, ElemInstance} from "./dom"; export interface Instance extends SVGElement {__element?: RawValue, __styles?: RawValue[], __sort?: RawValue} -export default class SVGWatcher extends DOMWatcher { +export class SVGWatcher extends DOMWatcher { tagPrefix = "svg"; createInstance(id:RawValue, element:RawValue, tagname:RawValue):Instance { @@ -35,3 +35,5 @@ export default class SVGWatcher extends DOMWatcher { super.setup(); } } + +Watcher.register("svg", SVGWatcher); diff --git a/src/watchers/system.ts b/src/watchers/system.ts index ec4aff1cb..3e442eca4 100644 --- a/src/watchers/system.ts +++ b/src/watchers/system.ts @@ -1,7 +1,7 @@ import {Watcher} from "./watcher"; import {ID} from "../runtime/runtime"; -export default class SystemWatcher extends Watcher { +export class SystemWatcher extends Watcher { timers:{[key:string]: {timer:any, prev:Date|undefined, frame:number}} = {}; getTime(changes:any[], timer:ID, frame:number, date?:Date) { @@ -50,3 +50,5 @@ export default class SystemWatcher extends Watcher { }) } } + +Watcher.register("system", SystemWatcher); diff --git a/src/watchers/tag-browser.ts b/src/watchers/tag-browser.ts index c66b6d914..bb0b325c7 100644 --- a/src/watchers/tag-browser.ts +++ b/src/watchers/tag-browser.ts @@ -1,7 +1,7 @@ import {Watcher, Program, RawMap, RawValue, RawEAVC} from "./watcher"; import {v4 as uuid} from "uuid"; -import UIWatcher from "../watchers/ui"; +import {UIWatcher} from "../watchers/ui"; interface Attrs extends RawMap {} @@ -19,7 +19,7 @@ function collapse(...args:T[]):T { return all; } -export default class TagBrowserWatcher extends Watcher { +export class TagBrowserWatcher extends Watcher { browser:Program = this.createTagBrowser(); setup() { @@ -322,3 +322,4 @@ export default class TagBrowserWatcher extends Watcher { } } +Watcher.register("tag browser", TagBrowserWatcher); diff --git a/src/watchers/ui.ts b/src/watchers/ui.ts index 75b6fc7a6..657379770 100644 --- a/src/watchers/ui.ts +++ b/src/watchers/ui.ts @@ -3,7 +3,7 @@ import {v4 as uuid} from "uuid"; export interface Attrs extends RawMap {} -export default class UIWatcher extends Watcher { +export class UIWatcher extends Watcher { protected static _addAttrs(id:string, attrs?: Attrs, eavs:RawEAV[] = []) { if(attrs) { for(let attr in attrs) { @@ -516,3 +516,5 @@ export default class UIWatcher extends Watcher { } } + +Watcher.register("ui", UIWatcher);