##// END OF EJS Templates
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already

File last commit:

r116:aac297dda27d v1.6.0 default
r131:c7d9ad82b374 v1.8.1 default
Show More
MainWidget.tsx
73 lines | 2.3 KiB | text/x-typescript | TypeScriptLexer
import { djbase, djclass } from "@implab/djx/declare";
import { DjxWidgetBase } from "@implab/djx/tsx/DjxWidgetBase";
import { bind, createElement, prop, watch, watchFor } from "@implab/djx/tsx";
import MainModel from "../model/MainModel";
import { Observable } from "@implab/djx/observable";
import { OrderedUpdate } from "@implab/djx/store";
import { Appointment } from "../model/Appointment";
import { LocalDate } from "@js-joda/core";
import Button = require("dijit/form/Button");
@djclass
export default class MainWidget extends djbase(DjxWidgetBase) {
appointments?: Observable<OrderedUpdate<Appointment>>;
model: MainModel;
dateTo?: LocalDate;
dateFrom?: LocalDate;
constructor(opts?: Partial<MainWidget> & ThisType<MainWidget>, srcNode?: string | Node) {
super(opts, srcNode);
const model = this.model = new MainModel();
this.own(model);
model.subscribe({ next: x => this.set(x) });
}
render() {
return <div className="tundra">
<h2 ref={bind("innerHTML", prop(this, "title"))} />
{watch(prop(this, "appointments"), items => items &&
<ul>
{watchFor(items, ({ id, title, getMembers }) =>
<li>{title}
<ul>
{watchFor(getMembers(), ({ role, name, position }) =>
<li className={role}>{name}({position})</li>
)}
</ul>
<div>
<Button onClick={() => this._onAddMemberClick(id)}>Add member</Button>
</div>
</li>
)}
</ul>
)}
<div>
<Button onClick={this._onAddAppointmentClick}>Add new appointment</Button>
</div>
</div>;
}
load() {
this.model.load();
}
private readonly _onAddMemberClick = (appointmentId: string) => {
this.model.addMember(appointmentId, {
email: "some-mail",
name: "Member Name",
position: "Member position",
role: "participant"
});
};
private readonly _onAddAppointmentClick = () => {
this.model.addAppointment("Appointment", new Date, 30);
};
}