sync-playground/sync/common.ts

16 lines
507 B
TypeScript

import { Comparator } from "./ordered-set.ts";
export type PeerId = string;
export type Tid = number;
export type Timestamp = [PeerId, Tid];
// deno-lint-ignore no-explicit-any
export const basicCompare: Comparator<any> = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
export const timestampCompare: Comparator<Timestamp> = (a, b) => {
const at = basicCompare(a[1], b[1]);
if (at !== 0) return at;
return basicCompare(a[0], b[0]);
};
export type Primitive = string | number | boolean | undefined | null;