_WidgetTests.ts
59 lines
| 1.1 KiB
| video/mp2t
|
TypeScriptLexer
|
|
r2 | import * as _WidgetBase from "dijit/_WidgetBase"; | ||
| import { watch } from "./traits"; | ||||
|
|
r1 | |||
| interface ScheduleWidgetAttrs { | ||||
| data: string[]; | ||||
| } | ||||
|
|
r2 | interface ScheduleWidgetEvents { | ||
| "scheduled": Event & { | ||||
| detail: { | ||||
| startDate: Date, | ||||
| endDate: Date | ||||
| } | ||||
| }; | ||||
| } | ||||
|
|
r1 | |||
|
|
r5 | class ScheduleWidget extends _WidgetBase<ScheduleWidgetAttrs, ScheduleWidgetEvents> { | ||
|
|
r1 | data: string[]; | ||
|
|
r5 | |||
| _onClick() { | ||||
|
|
r18 | this.set("data", ["", ""]); | ||
|
|
r5 | |||
| const t = this.get("title"); | ||||
| this.set({ | ||||
| data: ["",""] | ||||
| }); | ||||
| } | ||||
| render(){ | ||||
| watch(this, "title", v => String(v) ); | ||||
| } | ||||
|
|
r1 | } | ||
| const w = new ScheduleWidget({title: "Year schedule", data: ["a", "b"] }); | ||||
|
|
r2 | w.get("data"); | ||
|
|
r18 | w.set("data", ["a","b"]); | ||
|
|
r5 | w.set({ | ||
| data: ["a", "b"] | ||||
| }); | ||||
|
|
r2 | w.watch((p, o, n) => [p,o,n]); | ||
| w.watch("data", (p, o, n) => [p,o,n]); | ||||
| watch(w, "title", v => String(v) ); | ||||
| watch(w, "data", v => String(v) ); | ||||
| w.emit("scheduled", { detail: { startDate: new Date(), endDate: new Date()} }); | ||||
| w.emit("click", {} ); | ||||
| w.emit("click", {} ); | ||||
|
|
r10 | w.emit<any>("some-extra-event", {}); | ||
|
|
r2 | |||
| w.on("click", e => e); | ||||
|
|
r10 | w.on<any>("some-extra-event", e => e); | ||
