cleanup docs
This commit is contained in:
@@ -9,6 +9,7 @@ const bits8 = 0b11111111
|
||||
export default class BinaryEncoder {
|
||||
constructor () {
|
||||
// TODO: implement chained Uint8Array buffers instead of Array buffer
|
||||
// TODO: Rewrite all methods as functions!
|
||||
this.data = []
|
||||
}
|
||||
|
||||
|
||||
@@ -467,5 +467,4 @@ export default class Tree {
|
||||
}
|
||||
}
|
||||
}
|
||||
flush () {}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import ID from './ID/ID.js'
|
||||
import isParentOf from './isParentOf.js'
|
||||
|
||||
class ReverseOperation {
|
||||
constructor (y, transaction) {
|
||||
@@ -15,16 +16,6 @@ class ReverseOperation {
|
||||
}
|
||||
}
|
||||
|
||||
function isStructInScope (y, struct, scope) {
|
||||
while (struct !== y) {
|
||||
if (struct === scope) {
|
||||
return true
|
||||
}
|
||||
struct = struct._parent
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function applyReverseOperation (y, scope, reverseBuffer) {
|
||||
let performedUndo = false
|
||||
y.transact(() => {
|
||||
@@ -38,7 +29,7 @@ function applyReverseOperation (y, scope, reverseBuffer) {
|
||||
while (op._deleted && op._redone !== null) {
|
||||
op = op._redone
|
||||
}
|
||||
if (op._deleted === false && isStructInScope(y, op, scope)) {
|
||||
if (op._deleted === false && isParentOf(scope, op)) {
|
||||
performedUndo = true
|
||||
op._delete(y)
|
||||
}
|
||||
@@ -46,7 +37,7 @@ function applyReverseOperation (y, scope, reverseBuffer) {
|
||||
}
|
||||
for (let op of undoOp.deletedStructs) {
|
||||
if (
|
||||
isStructInScope(y, op, scope) &&
|
||||
isParentOf(scope, op) &&
|
||||
op._parent !== y &&
|
||||
(
|
||||
op._id.user !== y.userID ||
|
||||
|
||||
@@ -7,7 +7,15 @@ export default class YEvent {
|
||||
* @param {YType} target The changed type.
|
||||
*/
|
||||
constructor (target) {
|
||||
/**
|
||||
* The type on which this event was created on.
|
||||
* @type {YType}
|
||||
*/
|
||||
this.target = target
|
||||
/**
|
||||
* The current target on which the observe callback is called.
|
||||
* @type {YType}
|
||||
*/
|
||||
this.currentTarget = target
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* global crypto */
|
||||
|
||||
export function generateUserID () {
|
||||
export function generateRandomUint32 () {
|
||||
if (typeof crypto !== 'undefined' && crypto.getRandomValue != null) {
|
||||
// browser
|
||||
let arr = new Uint32Array(1)
|
||||
@@ -5,6 +5,8 @@
|
||||
* @param {Type} parent
|
||||
* @param {Type} child
|
||||
* @return {Boolean} Whether `parent` is a parent of `child`.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export default function isParentOf (parent, child) {
|
||||
child = child._parent
|
||||
|
||||
@@ -1,4 +1,22 @@
|
||||
|
||||
// TODO: rename mutex
|
||||
|
||||
/**
|
||||
* Creates a mutual exclude function with the following property:
|
||||
*
|
||||
* @example
|
||||
* const mutualExclude = createMutualExclude()
|
||||
* mutualExclude(function () {
|
||||
* // This function is immediately executed
|
||||
* mutualExclude(function () {
|
||||
* // This function is never executed, as it is called with the same
|
||||
* // mutualExclude
|
||||
* })
|
||||
* })
|
||||
*
|
||||
* @return {Function} A mutual exclude function
|
||||
* @public
|
||||
*/
|
||||
export function createMutualExclude () {
|
||||
var token = true
|
||||
return function mutualExclude (f) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import ID from './ID/ID.js'
|
||||
import RootID from './ID/RootID.js'
|
||||
|
||||
// TODO: Implement function to describe ranges
|
||||
|
||||
/**
|
||||
* A relative position that is based on the Yjs model. In contrast to an
|
||||
* absolute position (position by index), the relative position can be
|
||||
|
||||
@@ -11,16 +11,16 @@
|
||||
* a === b // values match
|
||||
*
|
||||
* @typedef {Object} SimpleDiff
|
||||
* @property {NaturalNumber} pos The index where changes were applied
|
||||
* @property {NaturalNumber} delete The number of characters to delete starting
|
||||
* @property {Number} pos The index where changes were applied
|
||||
* @property {Number} delete The number of characters to delete starting
|
||||
* at `index`.
|
||||
* @property {String} insert The new text to insert at `index` after applying
|
||||
* `delete`
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a diff between two strings. This diff implementation is intentionally
|
||||
* not very smart.
|
||||
* Create a diff between two strings. This diff implementation is highly
|
||||
* efficient, but not very sophisticated.
|
||||
*
|
||||
* @public
|
||||
* @param {String} a The old version of the string
|
||||
|
||||
@@ -12,15 +12,30 @@ import ItemEmbed from '../Struct/ItemEmbed.js'
|
||||
const structs = new Map()
|
||||
const references = new Map()
|
||||
|
||||
/**
|
||||
* Register a new Yjs types. The same type must be defined with the same
|
||||
* reference on all clients!
|
||||
*
|
||||
* @param {Number} reference
|
||||
* @param {class} structConstructor
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function registerStruct (reference, structConstructor) {
|
||||
structs.set(reference, structConstructor)
|
||||
references.set(structConstructor, reference)
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export function getStruct (reference) {
|
||||
return structs.get(reference)
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export function getStructReference (typeConstructor) {
|
||||
return references.get(typeConstructor)
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
|
||||
import YMap from '../Types/YMap'
|
||||
import YArray from '../Types/YArray'
|
||||
|
||||
export function writeObjectToYMap (object, type) {
|
||||
for (var key in object) {
|
||||
var val = object[key]
|
||||
if (Array.isArray(val)) {
|
||||
type.set(key, YArray)
|
||||
writeArrayToYArray(val, type.get(key))
|
||||
} else if (typeof val === 'object') {
|
||||
type.set(key, YMap)
|
||||
writeObjectToYMap(val, type.get(key))
|
||||
} else {
|
||||
type.set(key, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function writeArrayToYArray (array, type) {
|
||||
for (var i = array.length - 1; i >= 0; i--) {
|
||||
var val = array[i]
|
||||
if (Array.isArray(val)) {
|
||||
type.insert(0, [YArray])
|
||||
writeArrayToYArray(val, type.get(0))
|
||||
} else if (typeof val === 'object') {
|
||||
type.insert(0, [YMap])
|
||||
writeObjectToYMap(val, type.get(0))
|
||||
} else {
|
||||
type.insert(0, [val])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user