28 lines
585 B
JavaScript
28 lines
585 B
JavaScript
"use strict";
|
|
|
|
import { Dataspace, _Dataspace, currentFacet } from "@syndicate-lang/core";
|
|
const PRIORITY = _Dataspace.PRIORITY;
|
|
|
|
export function recorder(fields, fieldName, onCommit) {
|
|
let items = [];
|
|
|
|
function extend(item) {
|
|
items.push(item);
|
|
fields[fieldName] = true;
|
|
}
|
|
function commit() {
|
|
if (fields[fieldName]) {
|
|
onCommit(items);
|
|
reset();
|
|
}
|
|
}
|
|
function reset() {
|
|
items = [];
|
|
fields[fieldName] = false;
|
|
}
|
|
|
|
field fields[fieldName] = false;
|
|
currentFacet().addDataflow(commit, PRIORITY.IDLE);
|
|
return { extend, commit, reset };
|
|
}
|