UNPKG

@blinkk/selective-edit

Version:
57 lines (56 loc) 1.8 kB
/** * Generic key value manager for storing classes. */ /** * Generic class definition for the classes manager. */ export interface ClassComponent { /** * Classes can define any other properties and methods. */ [x: string]: any; } /** * Generic class constructor for the classes manager. */ export declare type ClassConstructor = new (...args: any[]) => any; /** * Class manager allowing for dynamically changing which class definitions are * used. Allows for defining a default set of classes which can later be * overwritten without special changes to the code. */ export declare class ClassManager<T, R> { DefaultCls?: T; classes: Record<string, T>; constructor(DefaultCls?: T); /** * Retrieve the class definition based on the key. * * @param key Key used to identify the purpose for the class. */ getByKey(key: string): T | null; /** * Create a new instance of a registered class if available. * * Falls back to the default class if it is defined or returns null if no * matching class definition is found. * * @param key Key used to identify the purpose for the class. * @param args Arguments to be passed onto the class constructor. */ newFromKey(key: string, ...args: any): R | null; /** * Register a new class that will be used when creating a new class * based on the provided key. * * @param key Key used to identify the purpose for the class. * @param Cls Class definition to use for the given key. */ registerClass(key: string, Cls: T): void; /** * Register multiple classes as a time. * * @param classes A mapping of keys to class definitions. */ registerClasses(classes: Record<string, T>): void; }