// filepath: /Users/rafasernavillanueva/code/coupons-plus/app/scripts/dashboard/src/tree/export/DelegatingBranchStoreExporter.ts import {BranchExporter} from "./Exporters"; import {BranchNode} from "../StateBranchNode"; export class DelegatingBranchExporter implements BranchExporter { constructor(private readonly exporters: BranchExporter[]) { } /** * Currently not used but here for completeness because this actually makes sense * in case we want to check if any of the exporters can handle the branch before calling export() */ canExport(branch: BranchNode): boolean { return this.exporters.some(exporter => exporter.canExport(branch)); } export(branch: BranchNode): string { for (const exporter of this.exporters) { if (exporter.canExport(branch)) { return exporter.export(branch); } } throw new Error("No BranchExporter shall handle the provided branch"); } } export const branchExporter = new DelegatingBranchExporter([]);