import * as Y from 'yjs'; import throttle from 'lodash.throttle'; export abstract class WavingDBDriver { abstract _getDoc(docId: string): Promise abstract _setDoc(docId: string, newDoc: Y.Doc, oldDoc?: Y.Doc, forceWrite?: boolean): Promise abstract close(): void; abstract setSessionRevision(docId: string, userToken: string, originalDocContent: Uint8Array): Promise; public setDoc: (docId: string, newDoc: Y.Doc, oldDoc?: Y.Doc, forceWrite?: boolean) => Promise; public getDoc: (docId: string) => Promise; private throttle: number; constructor({ throttleMs = 1000 }) { this.throttle = throttleMs; this.getDoc = this._getDoc; // const throttledSet = throttle((docId: string, newDoc: Y.Doc, oldDoc: Y.Doc) => { // this._setDoc(docId, newDoc, oldDoc); // }, throttleMs, { leading: false, trailing: true }); // this.setDoc = throttledSet; this.setDoc = async (docId, newDoc, oldDoc, forceWrite) => { // TODO: throttle this._setDoc(docId, newDoc, oldDoc, forceWrite); } } }