67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
namespace mod_platform.app.web
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export type type_state =
|
|
{
|
|
model : lib_mvc.type_model<mod_model.app.type_subject>;
|
|
element_dom : (null | HTMLElement);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export function make
|
|
(
|
|
model : lib_mvc.type_model<mod_model.app.type_subject>
|
|
) : type_state
|
|
{
|
|
return {
|
|
"model": model,
|
|
"element_dom": null,
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export function setup
|
|
(
|
|
platform : lib_mvc.type_model<type_state>,
|
|
target_dom : HTMLElement
|
|
) : Promise<void>
|
|
{
|
|
let fragment : DocumentFragment = lib_dom.request("app");
|
|
let app_dom : HTMLElement = fragment.querySelector(".app");
|
|
target_dom.appendChild(fragment);
|
|
|
|
app_dom.classList.add("empty");
|
|
|
|
platform.state.element_dom = app_dom;
|
|
|
|
// propagate events from the model
|
|
lib_mvc.model_listen<mod_model.app.type_subject, any>
|
|
(
|
|
platform.state.model,
|
|
(event) =>
|
|
{
|
|
return lib_mvc.model_notify<type_state, any>(platform, event);
|
|
}
|
|
);
|
|
|
|
return Promise.resolve<void>(undefined);
|
|
}
|
|
|
|
|
|
// imitate interface of model
|
|
// export function login(platform : lib_mvc.type_model<type_state>, username : string, password : string) : Promise<void> {return mod_model.app.login(platform.state.model, username, password);}
|
|
// export function logout(platform : lib_mvc.type_model<type_state>) : Promise<void> {return mod_model.app.logout(platform.state.model);}
|
|
// export function prepare_rental(platform : lib_mvc.type_model<type_state>) : Promise<void> {return mod_model.app.prepare_rental(platform.state.model);}
|
|
// function start_rental(platform : lib_mvc.type_model<type_state>, bike_name : string) : Promise<void> {return mod_model.app.start_rental(platform.model, bike_name);}
|
|
// function pause_rental(platform : lib_mvc.type_model<type_state>, bike_name : string) : Promise<void> {return mod_model.app.pause_rental(platform.model, bike_name);}
|
|
// function open_lock(platform : lib_mvc.type_model<type_state>, bike_name : string) : Promise<void> {return mod_model.app.open_lock(platform.model, bike_name);}
|
|
// function end_rental(platform : lib_mvc.type_model<type_state>, rental_id : mod_model.rental.type_id) : Promise<void> {return mod_model.app.end_rental(platform.model, rental_id);}
|
|
|
|
}
|