Skip to content
Permalink
Browse files
Implement experimental new encoder 🚀
  • Loading branch information
dmonad committed Jul 12, 2020
1 parent e31e968 commit 6c2cf0f7694da05542ce7e83bd7116889ce0868c
Show file tree
Hide file tree
Showing 36 changed files with 1,222 additions and 334 deletions.
@@ -17,10 +17,13 @@
"useCollapsibles": true,
"collapse": true,
"resources": {
"yjs.dev": "Yjs website"
"yjs.dev": "Website",
"docs.yjs.dev": "Docs",
"discuss.yjs.dev": "Forum",
"https://gitter.im/Yjs/community": "Chat"
},
"logo": {
"url": "https://user-images.githubusercontent.com/5553757/48975307-61efb100-f06d-11e8-9177-ee895e5916e5.png",
"url": "https://yjs.dev/images/logo/yjs-512x512.png",
"width": "162px",
"height": "162px",
"link": "/"
@@ -35,7 +38,7 @@
],
"default": {
"staticFiles": {
"include": ["examples/"]
"include": []
}
}
},
@@ -44,7 +47,6 @@
"encoding": "utf8",
"private": false,
"recurse": true,
"template": "./node_modules/tui-jsdoc-template",
"tutorials": "./examples"
"template": "./node_modules/tui-jsdoc-template"
}
}
@@ -958,5 +958,6 @@ Yjs and all related projects are [**MIT licensed**](./LICENSE).
Yjs is based on my research as a student at the [RWTH
i5](http://dbis.rwth-aachen.de/). Now I am working on Yjs in my spare time.

Fund this project by donating on [Patreon](https://www.patreon.com/dmonad) or
hiring [me](https://github.com/dmonad) for professional support.
Fund this project by donating on [GitHub Sponsors](https://github.com/sponsors/dmonad)
or hiring [me](https://github.com/dmonad) as a contractor for your collaborative
app.

Some generated files are not rendered by default. Learn more.

@@ -18,7 +18,7 @@
"lint": "markdownlint README.md && standard && tsc",
"docs": "rm -rf docs; jsdoc --configure ./.jsdoc.json --verbose --readme ./README.md --package ./package.json || true",
"serve-docs": "npm run docs && http-server ./docs/",
"preversion": "npm run lint && PRODUCTION=1 npm run dist && npm run docs && node ./dist/tests.cjs --repitition-time 1000",
"preversion": "npm run lint && PRODUCTION=1 npm run dist && npm run docs && node ./dist/tests.cjs --repitition-time 1000 && test -e dist/src/index.d.ts && test -e dist/yjs.cjs && test -e dist/yjs.cjs",
"debug": "concurrently 'http-server -o test.html' 'npm run watch'",
"trace-deopt": "clear && rollup -c && node --trace-deopt dist/test.cjs",
"trace-opt": "clear && rollup -c && node --trace-opt dist/test.cjs"
@@ -60,20 +60,20 @@
},
"homepage": "https://yjs.dev",
"dependencies": {
"lib0": "^0.2.29"
"lib0": "^0.2.32"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"concurrently": "^3.6.1",
"http-server": "^0.12.3",
"jsdoc": "^3.6.4",
"markdownlint-cli": "^0.23.1",
"markdownlint-cli": "^0.23.2",
"rollup": "^1.32.1",
"rollup-cli": "^1.0.9",
"standard": "^14.3.4",
"tui-jsdoc-template": "^1.2.2",
"typescript": "^3.9.3",
"typescript": "^3.9.6",
"y-protocols": "^0.2.3"
}
}
@@ -48,12 +48,18 @@ export {
typeMapGetSnapshot,
iterateDeletedStructs,
applyUpdate,
applyUpdateV2,
readUpdate,
readUpdateV2,
encodeStateAsUpdate,
encodeStateAsUpdateV2,
encodeStateVector,
encodeStateVectorV2,
UndoManager,
decodeSnapshot,
encodeSnapshot,
decodeSnapshotV2,
encodeSnapshotV2,
isDeleted,
isParentOf,
equalSnapshots,
@@ -1,6 +1,8 @@

export * from './utils/DeleteSet.js'
export * from './utils/Doc.js'
export * from './utils/UpdateDecoder.js'
export * from './utils/UpdateEncoder.js'
export * from './utils/encoding.js'
export * from './utils/EventHandler.js'
export * from './utils/ID.js'
@@ -1,9 +1,8 @@

import {
StructStore, ID, Transaction // eslint-disable-line
AbstractUpdateEncoder, ID, Transaction // eslint-disable-line
} from '../internals.js'

import * as encoding from 'lib0/encoding.js' // eslint-disable-line
import * as error from 'lib0/error.js'

export class AbstractStruct {
@@ -35,7 +34,7 @@ export class AbstractStruct {
}

/**
* @param {encoding.Encoder} encoder The encoder to write data to.
* @param {AbstractUpdateEncoder} encoder The encoder to write data to.
* @param {number} offset
* @param {number} encodingRef
*/
@@ -1,10 +1,7 @@
import {
Transaction, Item, StructStore // eslint-disable-line
AbstractUpdateDecoder, AbstractUpdateEncoder, Transaction, Item, StructStore // eslint-disable-line
} from '../internals.js'

import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'

export class ContentAny {
/**
* @param {Array<any>} arr
@@ -77,15 +74,15 @@ export class ContentAny {
*/
gc (store) {}
/**
* @param {encoding.Encoder} encoder
* @param {AbstractUpdateEncoder} encoder
* @param {number} offset
*/
write (encoder, offset) {
const len = this.arr.length
encoding.writeVarUint(encoder, len - offset)
encoder.writeLen(len - offset)
for (let i = offset; i < len; i++) {
const c = this.arr[i]
encoding.writeAny(encoder, c)
encoder.writeAny(c)
}
}

@@ -98,14 +95,14 @@ export class ContentAny {
}

/**
* @param {decoding.Decoder} decoder
* @param {AbstractUpdateDecoder} decoder
* @return {ContentAny}
*/
export const readContentAny = decoder => {
const len = decoding.readVarUint(decoder)
const len = decoder.readLen()
const cs = []
for (let i = 0; i < len; i++) {
cs.push(decoding.readAny(decoder))
cs.push(decoder.readAny())
}
return new ContentAny(cs)
}
@@ -1,10 +1,7 @@
import {
StructStore, Item, Transaction // eslint-disable-line
AbstractUpdateDecoder, AbstractUpdateEncoder, StructStore, Item, Transaction // eslint-disable-line
} from '../internals.js'

import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import * as buffer from 'lib0/buffer.js'
import * as error from 'lib0/error.js'

export class ContentBinary {
@@ -73,11 +70,11 @@ export class ContentBinary {
*/
gc (store) {}
/**
* @param {encoding.Encoder} encoder
* @param {AbstractUpdateEncoder} encoder
* @param {number} offset
*/
write (encoder, offset) {
encoding.writeVarUint8Array(encoder, this.content)
encoder.writeBuf(this.content)
}

/**
@@ -89,7 +86,7 @@ export class ContentBinary {
}

/**
* @param {decoding.Decoder} decoder
* @param {AbstractUpdateDecoder} decoder
* @return {ContentBinary}
*/
export const readContentBinary = decoder => new ContentBinary(buffer.copyUint8Array(decoding.readVarUint8Array(decoder)))
export const readContentBinary = decoder => new ContentBinary(decoder.readBuf())
@@ -1,12 +1,9 @@

import {
addToDeleteSet,
StructStore, Item, Transaction // eslint-disable-line
AbstractUpdateDecoder, AbstractUpdateEncoder, StructStore, Item, Transaction // eslint-disable-line
} from '../internals.js'

import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'

export class ContentDeleted {
/**
* @param {number} len
@@ -67,7 +64,7 @@ export class ContentDeleted {
* @param {Item} item
*/
integrate (transaction, item) {
addToDeleteSet(transaction.deleteSet, item.id, this.len)
addToDeleteSet(transaction.deleteSet, item.id.client, item.id.clock, this.len)
item.markDeleted()
}

@@ -80,11 +77,11 @@ export class ContentDeleted {
*/
gc (store) {}
/**
* @param {encoding.Encoder} encoder
* @param {AbstractUpdateEncoder} encoder
* @param {number} offset
*/
write (encoder, offset) {
encoding.writeVarUint(encoder, this.len - offset)
encoder.writeLen(this.len - offset)
}

/**
@@ -98,7 +95,7 @@ export class ContentDeleted {
/**
* @private
*
* @param {decoding.Decoder} decoder
* @param {AbstractUpdateDecoder} decoder
* @return {ContentDeleted}
*/
export const readContentDeleted = decoder => new ContentDeleted(decoding.readVarUint(decoder))
export const readContentDeleted = decoder => new ContentDeleted(decoder.readLen())
@@ -1,10 +1,8 @@

import {
StructStore, Item, Transaction // eslint-disable-line
AbstractUpdateDecoder, AbstractUpdateEncoder, StructStore, Item, Transaction // eslint-disable-line
} from '../internals.js'

import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import * as error from 'lib0/error.js'

/**
@@ -76,11 +74,11 @@ export class ContentEmbed {
*/
gc (store) {}
/**
* @param {encoding.Encoder} encoder
* @param {AbstractUpdateEncoder} encoder
* @param {number} offset
*/
write (encoder, offset) {
encoding.writeVarString(encoder, JSON.stringify(this.embed))
encoder.writeJSON(this.embed)
}

/**
@@ -94,7 +92,7 @@ export class ContentEmbed {
/**
* @private
*
* @param {decoding.Decoder} decoder
* @param {AbstractUpdateDecoder} decoder
* @return {ContentEmbed}
*/
export const readContentEmbed = decoder => new ContentEmbed(JSON.parse(decoding.readVarString(decoder)))
export const readContentEmbed = decoder => new ContentEmbed(decoder.readJSON())

0 comments on commit 6c2cf0f

Please sign in to comment.