Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ ot.Server = (function (global) {
this.setDocumentMaxLength(null);
}

/**
* @param {number | (() => number) | null} maxLength
*/
Server.prototype.setDocumentMaxLength = function (maxLength) {
this.documentMaxLength = maxLength;
};
Expand All @@ -34,10 +37,18 @@ ot.Server = (function (global) {

// ... and apply that on the document.
var newDocument = operation.apply(this.document);

const maxLen =
typeof this.documentMaxLength === "function"
? this.documentMaxLength()
: this.documentMaxLength;

// ignore if exceed the max length of document
if(typeof this.documentMaxLength === 'number' &&
newDocument.length > this.documentMaxLength &&
newDocument.length > this.document.length) {
if (
typeof maxLen === "number" &&
newDocument.length > maxLen &&
newDocument.length > this.document.length
) {
return;
}
this.document = newDocument;
Expand Down