const INITIALIZERS = Symbol.for('@revideo/2d/decorators/initializers'); export type Initializer = (instance: T, context?: any) => void; export function addInitializer(target: any, initializer: Initializer) { if (!target[INITIALIZERS]) { target[INITIALIZERS] = []; } else if ( // if one of the prototypes has initializers target[INITIALIZERS] && // and it's not the target object itself !Object.prototype.hasOwnProperty.call(target, INITIALIZERS) ) { const base = Object.getPrototypeOf(target); target[INITIALIZERS] = [...base[INITIALIZERS]]; } target[INITIALIZERS].push(initializer); } export function initialize(target: any, context?: any) { if (target[INITIALIZERS]) { try { target[INITIALIZERS].forEach((initializer: Initializer) => initializer(target, context), ); } catch (e: any) { e.inspect ??= target.key; throw e; } } }