add relevant relative positions exports

This commit is contained in:
Kevin Jahns 2021-01-13 01:16:21 +01:00
parent 7cbf204143
commit baca852733
2 changed files with 25 additions and 1 deletions

View File

@ -63,6 +63,9 @@ export {
encodeSnapshotV2,
decodeStateVector,
decodeStateVectorV2,
encodeRelativePosition,
decodeRelativePosition,
relativePositionToJSON,
isDeleted,
isParentOf,
equalSnapshots,

View File

@ -75,13 +75,34 @@ export class RelativePosition {
}
}
/**
* @param {RelativePosition} rpos
* @return {any}
*/
export const relativePositionToJSON = rpos => {
const json = {}
if (rpos.type) {
json.type = rpos.type
}
if (rpos.tname) {
json.tname = rpos.tname
}
if (rpos.item) {
json.item = rpos.item
}
if (rpos.assoc != null) {
json.assoc = rpos.assoc
}
return json
}
/**
* @param {any} json
* @return {RelativePosition}
*
* @function
*/
export const createRelativePositionFromJSON = json => new RelativePosition(json.type == null ? null : createID(json.type.client, json.type.clock), json.tname || null, json.item == null ? null : createID(json.item.client, json.item.clock))
export const createRelativePositionFromJSON = json => new RelativePosition(json.type == null ? null : createID(json.type.client, json.type.clock), json.tname || null, json.item == null ? null : createID(json.item.client, json.item.clock), json.assoc == null ? 0 : json.assoc)
export class AbsolutePosition {
/**