##// END OF EJS Templates
Added tag v1.9.0-rc5 for changeset 894b8239b953
Added tag v1.9.0-rc5 for changeset 894b8239b953

File last commit:

r118:e07418577cbc v1.6.1 default
r143:62b21ca84dce default
Show More
MainContext.ts
88 lines | 2.6 KiB | video/mp2t | TypeScriptLexer
cin
Working on WatchForRendition
r107 import Memory = require("dojo/store/Memory");
import Observable = require("dojo/store/Observable");
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 import { Appointment, AppointmentRole, Member } from "./Appointment";
cin
Working on WatchForRendition
r107 import { Contact } from "./Contact";
import { Uuid } from "@implab/core-amd/Uuid";
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 import { IDestroyable } from "@implab/core-amd/interfaces";
import { delay } from "@implab/core-amd/safe";
cin
added reduce() and next() methods to observable...
r116 import { query } from "@implab/djx/store";
cin
Working on WatchForRendition
r107
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 type AppointmentRecord = Omit<Appointment, "getMembers"> & { id: string };
cin
Working on WatchForRendition
r107
type ContactRecord = Contact;
type MemberRecord = Member & { appointmentId: string; };
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 const item = <T, T2>(map: (x: T) => T2) => <U extends { item: T }>({ item, ...props }: U) => ({ item: map(item), ...props });
cin
Working on WatchForRendition
r107
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 export class MainContext implements IDestroyable {
cin
linting
r109 private readonly _appointments = new Observable(new Memory<AppointmentRecord>());
cin
Working on WatchForRendition
r107
cin
linting
r109 private readonly _contacts = new Observable(new Memory<ContactRecord>());
cin
Working on WatchForRendition
r107
cin
linting
r109 private readonly _members = new Observable(new Memory<MemberRecord>());
cin
Working on WatchForRendition
r107
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 async createAppointment(title: string, startAt: Date, duration: number, members: Member[]) {
await delay(1000);
cin
Working on WatchForRendition
r107 const id = Uuid();
this._appointments.add({
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 id,
cin
Working on WatchForRendition
r107 startAt,
duration,
title
});
members.forEach(member =>
this._members.add({
appointmentId: id,
...member
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 }, { id: Uuid() }) as void
cin
Working on WatchForRendition
r107 );
}
cin
added whenRendered() method to wait for pending oprations to complete
r118 async load() {
await Promise.resolve();
for (let i = 0; i < 2; i++) {
const id = Uuid();
this._appointments.add({
id,
startAt: new Date(),
duration: 30,
title: `Hello ${i+1}`
});
}
}
cin
added reduce() and next() methods to observable...
r116 private readonly _queryAppointmentsRx = query(this._appointments);
private readonly _queryMembersRx = query(this._members);
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 queryAppointments({ dateFrom, dateTo }: { dateFrom?: Date; dateTo?: Date; } = {}) {
cin
added reduce() and next() methods to observable...
r116 return this._queryAppointmentsRx(({ startAt }) =>
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 (!dateFrom || dateFrom <= startAt) &&
(!dateTo || startAt <= dateTo)
).map(item(this._mapAppointment));
cin
Working on WatchForRendition
r107 }
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 async addMember(appointmentId: string, member: Member) {
await delay(1000);
this._members.add({
appointmentId,
...member
});
}
cin
Working on WatchForRendition
r107
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 private readonly _mapAppointment = ({ startAt, title, duration, id }: AppointmentRecord) => ({
id,
title,
startAt,
duration,
cin
added reduce() and next() methods to observable...
r116 getMembers: (role?: AppointmentRole) => this._queryMembersRx(role ? { appointmentId: id, role } : { appointmentId: id })
cin
linting
r109 });
cin
Working on WatchForRendition
r107
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 destroy() {
}
cin
Working on WatchForRendition
r107 }