diff --git a/README.md b/README.md index e482fe17..d859b7f5 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,6 @@ Sponsorship also comes with special perks! [![Become a Sponsor](https://img.shie * [Document Updates](#Document-Updates) * [Relative Positions](#Relative-Positions) * [Y.UndoManager](#YUndoManager) -* [Miscellaneous](#Miscellaneous) - * [Typescript Declarations](#Typescript-Declarations) * [Yjs CRDT Algorithm](#Yjs-CRDT-Algorithm) * [License and Author](#License-and-Author) @@ -867,24 +865,6 @@ undoManager.on('stack-item-popped', event => { }) ``` -## Miscellaneous - -### Typescript Declarations - -Yjs has type descriptions. But until [this -ticket](https://github.com/Microsoft/TypeScript/issues/7546) is fixed, this is -how you can make use of Yjs type declarations. - -```json -{ - "compilerOptions": { - "allowJs": true, - "checkJs": true, - }, - "maxNodeModuleJsDepth": 5 -} -``` - ## Yjs CRDT Algorithm *Conflict-free replicated data types* (CRDT) for collaborative editing are an diff --git a/src/utils/Doc.js b/src/utils/Doc.js index 4eab58f7..60c934e2 100644 --- a/src/utils/Doc.js +++ b/src/utils/Doc.js @@ -126,45 +126,45 @@ export class Doc extends Observable { /** * @template T - * @param {string} name + * @param {string} [name] * @return {YArray} * * @public */ - getArray (name) { + getArray (name = '') { // @ts-ignore return this.get(name, YArray) } /** - * @param {string} name + * @param {string} [name] * @return {YText} * * @public */ - getText (name) { + getText (name = '') { // @ts-ignore return this.get(name, YText) } /** - * @param {string} name + * @param {string} [name] * @return {YMap} * * @public */ - getMap (name) { + getMap (name = '') { // @ts-ignore return this.get(name, YMap) } /** - * @param {string} name + * @param {string} [name] * @return {YXmlFragment} * * @public */ - getXmlFragment (name) { + getXmlFragment (name = '') { // @ts-ignore return this.get(name, YXmlFragment) } diff --git a/src/utils/encoding.js b/src/utils/encoding.js index bc3fed33..db001227 100644 --- a/src/utils/encoding.js +++ b/src/utils/encoding.js @@ -152,7 +152,7 @@ export const readClientsStructRefs = (decoder, clientRefs, doc) => { const struct = new Item( createID(client, clock), null, origin, null, rightOrigin, - canCopyParentInfo && !hasParentYKey ? decoder.readLeftID() : (parentYKey ? doc.get(parentYKey) : null), // parent + canCopyParentInfo && !hasParentYKey ? decoder.readLeftID() : (parentYKey !== null ? doc.get(parentYKey) : null), // parent canCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoder.readString() : null, // parentSub /** @type {AbstractContent} */ (readItemContent(decoder, info)) // item content ) diff --git a/tests/consistency.tests.js b/tests/doc.tests.js similarity index 61% rename from tests/consistency.tests.js rename to tests/doc.tests.js index 4743ec74..d07e503c 100644 --- a/tests/consistency.tests.js +++ b/tests/doc.tests.js @@ -17,3 +17,16 @@ export const testClientIdDuplicateChange = tc => { Y.applyUpdate(doc2, Y.encodeStateAsUpdate(doc1)) t.assert(doc2.clientID !== doc1.clientID) } + +/** + * @param {t.TestCase} tc + */ +export const testGetTypeEmptyId = tc => { + const doc1 = new Y.Doc() + doc1.getText('').insert(0, 'h') + doc1.getText().insert(1, 'i') + const doc2 = new Y.Doc() + Y.applyUpdate(doc2, Y.encodeStateAsUpdate(doc1)) + t.assert(doc2.getText().toString() === 'hi') + t.assert(doc2.getText('').toString() === 'hi') +} diff --git a/tests/index.js b/tests/index.js index 6d019cfc..c07f1677 100644 --- a/tests/index.js +++ b/tests/index.js @@ -6,7 +6,7 @@ import * as xml from './y-xml.tests.js' import * as encoding from './encoding.tests.js' import * as undoredo from './undo-redo.tests.js' import * as compatibility from './compatibility.tests.js' -import * as consistency from './consistency.tests.js' +import * as doc from './doc.tests.js' import { runTests } from 'lib0/testing.js' import { isBrowser, isNode } from 'lib0/environment.js' @@ -16,7 +16,7 @@ if (isBrowser) { log.createVConsole(document.body) } runTests({ - map, array, text, xml, consistency, encoding, undoredo, compatibility + map, array, text, xml, doc, encoding, undoredo, compatibility }).then(success => { /* istanbul ignore next */ if (isNode) {