2019-05-30 22:06:15 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-06-07 13:20:45 +00:00
|
|
|
import { Dataspace, _Dataspace, currentFacet } from "@syndicate-lang/core";
|
2019-05-30 22:06:15 +00:00
|
|
|
const PRIORITY = _Dataspace.PRIORITY;
|
|
|
|
|
2019-06-08 20:10:31 +00:00
|
|
|
export function recorder(fields, fieldName, onCommit) {
|
|
|
|
let items = [];
|
|
|
|
|
2019-06-07 14:51:13 +00:00
|
|
|
function extend(item) {
|
2019-06-08 20:10:31 +00:00
|
|
|
items.push(item);
|
2019-06-07 14:51:13 +00:00
|
|
|
fields[fieldName] = true;
|
|
|
|
}
|
|
|
|
function commit() {
|
2019-05-30 22:06:15 +00:00
|
|
|
if (fields[fieldName]) {
|
2019-06-08 20:10:31 +00:00
|
|
|
onCommit(items);
|
2019-06-08 20:50:11 +00:00
|
|
|
reset();
|
2019-05-30 22:06:15 +00:00
|
|
|
}
|
2019-06-07 14:51:13 +00:00
|
|
|
}
|
2019-06-08 20:50:11 +00:00
|
|
|
function reset() {
|
|
|
|
items = [];
|
|
|
|
fields[fieldName] = false;
|
|
|
|
}
|
2019-06-07 14:51:13 +00:00
|
|
|
|
|
|
|
field fields[fieldName] = false;
|
|
|
|
currentFacet().addDataflow(commit, PRIORITY.IDLE);
|
2019-06-08 20:50:11 +00:00
|
|
|
return { extend, commit, reset };
|
2019-05-30 22:06:15 +00:00
|
|
|
}
|