Junyi 139ca9a635
refactor(plugin-formula): combine 2 formula field type into 1 (#1457)
* fix: observer

* refactor(plugin-formula): merge 2 formula field type

* fix(plugin-formula): fix types

* fix(plugin-formula): fix type

* fix(plugin-formula): fix formulajs version

* fix(plugin-formula): change to VariableInput to avoid range error

* test(plugin-formula): add test

* fix(plugin-formula): fix test case

* fix(plugin-formula): fix test case

* fix(plugin-formula): fix test case

* refactor(plugin-formula): move components into plugin

* fix(plugin-formula): fix migration

* fix(plugin-formula): revert legacy component to fix build

* fix(plugin-formula): fix test case

* fix(plugin-formula): fix test case

* fix(plugin-formula): fix read-pretty component

* fix(plugin-formula): fix formula result component

* feat(plugin-formula): add checkbox display X

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
2023-02-21 20:12:21 +08:00

45 lines
1015 B
TypeScript

export interface RegistryOptions {
override: boolean;
}
export class Registry<T> {
private map = new Map<string, T>();
options: RegistryOptions;
constructor(options: RegistryOptions = { override: false }) {
this.options = options;
}
public register(key: string, value: T): void {
if (!this.options.override && this.map.has(key)) {
throw new Error(`this registry does not allow to override existing keys: "${key}"`);
}
this.map.set(key, value);
}
// async import({ directory, extensions = ['.js', '.ts', '.json'] }) {
// const files = await fs.readdir(directory);
// return files.filter(file => extensions.includes(path.extname(file)))
// }
public get(key: string): T {
return this.map.get(key);
}
public getKeys(): Iterable<string> {
return this.map.keys();
}
public getValues(): Iterable<T> {
return this.map.values();
}
public getEntities(): Iterable<[string, T]> {
return this.map.entries();
}
}
export default Registry;