export function createFormulaBindingInstanceTableRebuildController(args) {
    let needsRebuild = false;
    const ensureFreshNow = () => {
        if (!needsRebuild) {
            return;
        }
        needsRebuild = false;
        args.rebuildFormulaInstancesNow();
    };
    return {
        deferRebuildNow() {
            args.formulaInstances.clear();
            needsRebuild = true;
        },
        clearRebuildNow() {
            needsRebuild = false;
        },
        recordIfMissingOrRebuildingNow(cellIndex, source, templateId, ownerPosition) {
            if (needsRebuild || !args.formulaInstances.get(cellIndex)) {
                args.recordFormulaInstanceNow(cellIndex, source, templateId, ownerPosition);
            }
        },
        upsertFreshFormulaInstancesNow(records) {
            if (!needsRebuild) {
                args.formulaInstances.upsertMany(records);
            }
        },
        hydrateFreshFormulaInstancesNow(records) {
            needsRebuild = false;
            args.formulaInstances.hydrate(records);
        },
        exportFormulaInstancesNow() {
            ensureFreshNow();
            return args.formulaInstances.list();
        },
    };
}
//# sourceMappingURL=formula-binding-instance-table-rebuild.js.map