UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

35 lines (34 loc) 902 B
import { encode as l, decode as u } from "json-joy/lib/json-crdt-patch/codec/compact"; function s(e) { return new TextEncoder().encode(JSON.stringify(e)).length; } function p(e) { const o = u(e), t = o.getId(), c = o.span(); return [[t?.sid, t.time + c]]; } function P(e, o) { if (!e.ops || e.ops.length === 0) return []; const t = l(e), c = s(t); if (c <= o) return [t]; if (e.ops.length == 1) return console.warn( `Patch is too large (${c} B) but cannot be split further since it only contains one operation.` ), [t]; const a = t[0], i = []; let n = [a]; for (let r = 1; r < t.length; r += 1) { const h = n.length - 1; s([ ...n, t[r] ]) > o && h > 0 && (i.push(n), n = [p(n)]), n.push(t[r]); } return n.length > 1 && i.push(n), i; } export { s as getPatchSizeInBytes, P as splitPatch }; //# sourceMappingURL=splitPatch.js.map