2019-09-14 22:06:46 +00:00
|
|
|
//-------------------------------------
|
2019-07-11 13:57:06 +00:00
|
|
|
// INITIALIZING NEW CONTEXT
|
2019-09-14 22:06:46 +00:00
|
|
|
//-------------------------------------
|
2024-05-03 18:31:14 +00:00
|
|
|
import type { Context } from "./Context.js";
|
2019-07-11 13:57:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of callbacks to invoke when a new context is created
|
|
|
|
*/
|
|
|
|
const notifyNewContext: Array<(ctx: Context) => void> = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used internally to setup a new Context
|
|
|
|
*/
|
|
|
|
export function onContextInit(cb: (ctx: Context) => void): void {
|
|
|
|
notifyNewContext.push(cb);
|
|
|
|
}
|
|
|
|
|
2019-07-16 19:41:59 +00:00
|
|
|
/**
|
|
|
|
* Invoke any classes which need to also be initialized when a new context is created.
|
|
|
|
*/
|
2019-07-11 13:57:06 +00:00
|
|
|
export function initializeContext(ctx: Context): void {
|
|
|
|
// add any additional modules
|
2024-05-03 18:31:14 +00:00
|
|
|
notifyNewContext.forEach((cb) => cb(ctx));
|
2019-07-11 13:57:06 +00:00
|
|
|
}
|
2019-07-16 19:41:59 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-26 03:15:42 +00:00
|
|
|
* Array of callbacks to invoke when a new context is closed
|
2019-07-16 19:41:59 +00:00
|
|
|
*/
|
|
|
|
const notifyCloseContext: Array<(ctx: Context) => void> = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used internally to tear down a Context
|
|
|
|
*/
|
|
|
|
export function onContextClose(cb: (ctx: Context) => void): void {
|
|
|
|
notifyCloseContext.push(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function closeContext(ctx: Context): void {
|
2021-02-26 03:15:42 +00:00
|
|
|
// remove any additional modules
|
2024-05-03 18:31:14 +00:00
|
|
|
notifyCloseContext.forEach((cb) => cb(ctx));
|
2019-07-16 19:41:59 +00:00
|
|
|
}
|