bug fixes, and performance improvements, and drawer
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/** Stable across database Dates, JSON SSE payloads, and Nuxt hydration. */
|
||||
export const serializeTopicSnapshot = (topic: unknown): string => JSON.stringify(topic, (_key, value) => {
|
||||
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return Object.fromEntries(Object.keys(value).sort().map(key => [key, value[key]]));
|
||||
});
|
||||
|
||||
/** Absolute offsets make replay across a snapshot boundary idempotent. */
|
||||
export const appendTextDelta = (current: string, content: string, offset?: number): string => {
|
||||
if (offset === undefined) {
|
||||
return current + content;
|
||||
}
|
||||
if (offset > current.length) {
|
||||
// A gap requires reconciliation, not silently concatenating corrupt text.
|
||||
return current;
|
||||
}
|
||||
const overlap = current.length - offset;
|
||||
return overlap >= content.length ? current : current + content.slice(overlap);
|
||||
};
|
||||
Reference in New Issue
Block a user