mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 13:43:03 -05:00
1f8f4bf539
* Add more loaders so we can track the progress better * fix lint
34 lines
885 B
TypeScript
34 lines
885 B
TypeScript
class RemoteComponentsLibrary {
|
|
private components: Record<string, ComponentNode | ComponentSetNode> = {};
|
|
private queue: string[] = [];
|
|
|
|
public register(id: string, component: ComponentNode | ComponentSetNode) {
|
|
if (!Object.prototype.hasOwnProperty.call(this.components, id)) {
|
|
this.queue.push(id);
|
|
}
|
|
|
|
this.components[id] = component;
|
|
}
|
|
|
|
public get(id: string): ComponentNode | ComponentSetNode | undefined {
|
|
return this.components[id];
|
|
}
|
|
|
|
public next(): ComponentNode | ComponentSetNode {
|
|
const lastKey = this.queue.pop();
|
|
|
|
if (!lastKey) throw new Error('No components to pop');
|
|
|
|
return this.components[lastKey];
|
|
}
|
|
|
|
public remaining(): number {
|
|
return this.queue.length;
|
|
}
|
|
|
|
public total(): number {
|
|
return Object.keys(this.components).length;
|
|
}
|
|
}
|
|
|
|
export const remoteComponentLibrary = new RemoteComponentsLibrary();
|