overleaf/libraries/overleaf-editor-core/lib/change_note.js
Eric Mc Sween d54bcc4aa9 Merge pull request #14418 from overleaf/em-history-lib-es6-classes
Move overleaf-editor-core code to ES6 classes

GitOrigin-RevId: f9b50579aec0cef9d9e6aefcfcb3e380fae4b6f4
2023-08-23 08:05:34 +00:00

61 lines
1.2 KiB
JavaScript

'use strict'
const assert = require('check-types').assert
const Change = require('./change')
/**
* A `ChangeNote` is returned when the server has applied a {@link Change}.
*/
class ChangeNote {
/**
* @param {number} baseVersion the new base version for the change
* @param {?Change} change
*/
constructor(baseVersion, change) {
assert.integer(baseVersion, 'bad baseVersion')
assert.maybe.instance(change, Change, 'bad change')
this.baseVersion = baseVersion
this.change = change
}
/**
* For serialization.
*
* @return {Object}
*/
toRaw() {
return {
baseVersion: this.baseVersion,
change: this.change.toRaw(),
}
}
toRawWithoutChange() {
return {
baseVersion: this.baseVersion,
}
}
static fromRaw(raw) {
assert.integer(raw.baseVersion, 'bad raw.baseVersion')
assert.maybe.object(raw.change, 'bad raw.changes')
return new ChangeNote(raw.baseVersion, Change.fromRaw(raw.change))
}
getBaseVersion() {
return this.baseVersion
}
getResultVersion() {
return this.baseVersion + 1
}
getChange() {
return this.change
}
}
module.exports = ChangeNote