mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-27 03:53:07 +00:00
aaf880c925
* WIP moving tests to web-test-runner * updating thresholds * Adding file extensions * Testing integrations * linting * fixing dep * moving back to root dir * prettier all of the files * updating eslint rules to use with prettier * remove import package * moving tsignore around * removing unneeded ignores * all tests run on puppeteer, no need for testing guards * linting * import type syntax * cleaning up * Update package.json
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
//-------------------------------------
|
|
// INITIALIZING NEW CONTEXT
|
|
//-------------------------------------
|
|
import type { Context } from "./Context.js";
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
/**
|
|
* Invoke any classes which need to also be initialized when a new context is created.
|
|
*/
|
|
export function initializeContext(ctx: Context): void {
|
|
// add any additional modules
|
|
notifyNewContext.forEach((cb) => cb(ctx));
|
|
}
|
|
|
|
/**
|
|
* Array of callbacks to invoke when a new context is closed
|
|
*/
|
|
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 {
|
|
// remove any additional modules
|
|
notifyCloseContext.forEach((cb) => cb(ctx));
|
|
}
|