55 lines
660 B
TypeScript
55 lines
660 B
TypeScript
namespace formgen.ioc
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export class trait_notification<type_value>
|
|
{
|
|
|
|
/**
|
|
*/
|
|
private handlers : Array<type_handler<type_value>>;
|
|
|
|
|
|
/**
|
|
*/
|
|
public constructor(
|
|
handlers : Array<type_handler<type_value>>
|
|
)
|
|
{
|
|
this.handlers = handlers;
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
public listen(
|
|
handler : type_handler<type_value>
|
|
) : void
|
|
{
|
|
this.handlers.push(handler);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
public async notify(
|
|
value : type_value
|
|
) : Promise<void>
|
|
{
|
|
return (
|
|
Promise.all<void>(
|
|
this.handlers.map(
|
|
handler => handler(value)
|
|
)
|
|
)
|
|
.then(
|
|
() => Promise.resolve<void>(undefined)
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
}
|