synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
46 lines (45 loc) • 1.22 kB
JavaScript
import { s as o } from "json-joy/lib/json-crdt-patch";
function l(t, e, r) {
let a;
return Object.hasOwn(t, e) ? a = t[e] : r[e]?.isRequired ? a = null : a = void 0, a;
}
function p(t, e, r) {
const a = t.api.arr(["rows"]), { columnNames: n } = t.api.getSnapshot();
switch (e.type) {
case "CREATE": {
const s = n.map(
(i) => o.con(
l(e.rowData, i, r)
)
);
a?.ins(e.rowIndex, [
o.obj({ data: o.vec(...s), metadata: o.obj({}) })
]);
break;
}
case "DELETE":
a?.del(e.rowIndex, e.count ?? 1);
break;
case "UPDATE": {
Object.entries(e.updatedData).forEach(([s, i]) => {
if (s.startsWith("_")) return;
const c = n.indexOf(s);
c !== -1 && t.api.vec([
"rows",
String(e.rowIndex),
"data"
])?.set([[c, o.con(i)]]);
});
break;
}
case "SET_SELECTION": {
t.api.obj().has("selection") || t.api.obj().add(["selection"], o.obj({})), t.api.obj(["selection"]).set({ [e.replicaId]: o.con(e.selection) });
break;
}
}
}
export {
p as applyModelChange,
l as getDefaultValueForProperty
};
//# sourceMappingURL=applyModelChange.js.map