121 lines
1.6 KiB
TypeScript
121 lines
1.6 KiB
TypeScript
namespace mod_model.rental
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export type type_id = string;
|
|
|
|
|
|
/**
|
|
*/
|
|
export enum enum_condition
|
|
{
|
|
prior,
|
|
running,
|
|
paused,
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export type type_subject =
|
|
{
|
|
id : type_id;
|
|
condition : enum_condition;
|
|
bike_name : (null | string);
|
|
};
|
|
|
|
|
|
/**
|
|
*/
|
|
export function initial
|
|
(
|
|
id : type_id
|
|
) : type_subject
|
|
{
|
|
return {
|
|
"id": id,
|
|
"condition": enum_condition.prior,
|
|
"bike_name": null,
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function start
|
|
(
|
|
model : lib_mvc.type_model<type_subject>,
|
|
bike_name : string
|
|
) : Promise<void>
|
|
{
|
|
model.state.condition = enum_condition.running;
|
|
model.state.bike_name = bike_name;
|
|
await lib_mvc.model_notify<type_subject, {id : type_id}>
|
|
(
|
|
model,
|
|
{
|
|
"type": "start",
|
|
"data": {"id": model.state.id}
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function pause
|
|
(
|
|
model : lib_mvc.type_model<type_subject>
|
|
) : Promise<void>
|
|
{
|
|
model.state.condition = enum_condition.paused;
|
|
await lib_mvc.model_notify<type_subject, {id : type_id}>
|
|
(
|
|
model,
|
|
{
|
|
"type": "pause",
|
|
"data": {"id": model.state.id}
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function open
|
|
(
|
|
model : lib_mvc.type_model<type_subject>
|
|
) : Promise<void>
|
|
{
|
|
model.state.condition = enum_condition.running;
|
|
await lib_mvc.model_notify<type_subject, {id : type_id}>
|
|
(
|
|
model,
|
|
{
|
|
"type": "open",
|
|
"data": {"id": model.state.id}
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function end
|
|
(
|
|
model : lib_mvc.type_model<type_subject>
|
|
) : Promise<void>
|
|
{
|
|
await lib_mvc.model_notify<type_subject, {id : type_id}>
|
|
(
|
|
model,
|
|
{
|
|
"type": "end",
|
|
"data": {"id": model.state.id}
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|