Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce3b0f3043 | ||
|
|
94646b2f45 | ||
|
|
29c2ad4492 | ||
|
|
637fadf38e | ||
|
|
0c6c11d583 | ||
|
|
6f9a2c9df7 | ||
|
|
7876a96163 | ||
|
|
22653c799c | ||
|
|
68109b033f | ||
|
|
38eb2e502c |
11
README.md
11
README.md
@@ -570,6 +570,10 @@ calls. I.e. <code>doc.transact(() => { yarray.insert(..); ymap.set(..) })</code>
|
|||||||
triggers a single change event. <br>You can specify an optional <code>origin</code>
|
triggers a single change event. <br>You can specify an optional <code>origin</code>
|
||||||
parameter that is stored on <code>transaction.origin</code> and
|
parameter that is stored on <code>transaction.origin</code> and
|
||||||
<code>on('update', (update, origin) => ..)</code>.
|
<code>on('update', (update, origin) => ..)</code>.
|
||||||
|
</dd>
|
||||||
|
<b><code>toJSON():any</code><b>
|
||||||
|
<dd>
|
||||||
|
Converts the entire document into a js object, recursively traversing each yjs type.
|
||||||
</dd>
|
</dd>
|
||||||
<b><code>get(string, Y.[TypeClass]):[Type]</code></b>
|
<b><code>get(string, Y.[TypeClass]):[Type]</code></b>
|
||||||
<dd>Define a shared type.</dd>
|
<dd>Define a shared type.</dd>
|
||||||
@@ -597,6 +601,13 @@ peers. You can apply document updates in any order and multiple times.
|
|||||||
<dd>Emitted before each transaction.</dd>
|
<dd>Emitted before each transaction.</dd>
|
||||||
<b><code>on('afterTransaction', function(Y.Transaction, Y.Doc):void)</code></b>
|
<b><code>on('afterTransaction', function(Y.Transaction, Y.Doc):void)</code></b>
|
||||||
<dd>Emitted after each transaction.</dd>
|
<dd>Emitted after each transaction.</dd>
|
||||||
|
<b><code>on('beforeAllTransactions', function(Y.Doc):void)</code></b>
|
||||||
|
<dd>
|
||||||
|
Transactions can be nested (e.g. when an event within a transaction calls another
|
||||||
|
transaction). Emitted before the first transaction.
|
||||||
|
</dd>
|
||||||
|
<b><code>on('afterAllTransactions', function(Y.Doc, Array<Y.Transaction>):void)</code></b>
|
||||||
|
<dd>Emitted after the last transaction is cleaned up.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
### Document Updates
|
### Document Updates
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.3.0",
|
"version": "13.3.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.3.0",
|
"version": "13.3.2",
|
||||||
"description": "Shared Editing Library",
|
"description": "Shared Editing Library",
|
||||||
"main": "./dist/yjs.cjs",
|
"main": "./dist/yjs.cjs",
|
||||||
"module": "./dist/yjs.mjs",
|
"module": "./dist/yjs.mjs",
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
ContentAny,
|
ContentAny,
|
||||||
ContentBinary,
|
ContentBinary,
|
||||||
getItemCleanStart,
|
getItemCleanStart,
|
||||||
AbstractUpdateEncoder, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, // eslint-disable-line
|
YText, YArray, AbstractUpdateEncoder, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as map from 'lib0/map.js'
|
import * as map from 'lib0/map.js'
|
||||||
@@ -19,7 +19,7 @@ import * as iterator from 'lib0/iterator.js'
|
|||||||
import * as error from 'lib0/error.js'
|
import * as error from 'lib0/error.js'
|
||||||
import * as math from 'lib0/math.js'
|
import * as math from 'lib0/math.js'
|
||||||
|
|
||||||
const maxSearchMarker = 60
|
const maxSearchMarker = 80
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A unique timestamp that identifies each marker.
|
* A unique timestamp that identifies each marker.
|
||||||
@@ -152,11 +152,12 @@ export const findMarker = (yarray, index) => {
|
|||||||
// if (marker) {
|
// if (marker) {
|
||||||
// if (window.lengthes == null) {
|
// if (window.lengthes == null) {
|
||||||
// window.lengthes = []
|
// window.lengthes = []
|
||||||
|
// window.getLengthes = () => window.lengthes.sort((a, b) => a - b)
|
||||||
// }
|
// }
|
||||||
// window.lengthes.push(marker.index - pindex)
|
// window.lengthes.push(marker.index - pindex)
|
||||||
// console.log('distance', marker.index - pindex, 'len', p && p.parent.length)
|
// console.log('distance', marker.index - pindex, 'len', p && p.parent.length)
|
||||||
// }
|
// }
|
||||||
if (marker !== null && math.abs(marker.index - pindex) < 30) {
|
if (marker !== null && math.abs(marker.index - pindex) < /** @type {YText|YArray<any>} */ (p.parent).length / maxSearchMarker) {
|
||||||
// adjust existing marker
|
// adjust existing marker
|
||||||
overwriteMarker(marker, p, pindex)
|
overwriteMarker(marker, p, pindex)
|
||||||
return marker
|
return marker
|
||||||
|
|||||||
@@ -782,8 +782,7 @@ export class YText extends AbstractType {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
iterateStructs(transaction, /** @type {Array<Item|GC>} */ (doc.store.clients.get(client)), clock, afterClock, item => {
|
iterateStructs(transaction, /** @type {Array<Item|GC>} */ (doc.store.clients.get(client)), clock, afterClock, item => {
|
||||||
// @ts-ignore
|
if (!item.deleted && /** @type {Item} */ (item).content.constructor === ContentFormat) {
|
||||||
if (item.content.constructor === ContentFormat) {
|
|
||||||
foundFormattingItem = true
|
foundFormattingItem = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -337,6 +337,7 @@ const cleanupTransactions = (transactionCleanups, i) => {
|
|||||||
}
|
}
|
||||||
if (transactionCleanups.length <= i + 1) {
|
if (transactionCleanups.length <= i + 1) {
|
||||||
doc._transactionCleanups = []
|
doc._transactionCleanups = []
|
||||||
|
doc.emit('afterAllTransactions', [doc, transactionCleanups])
|
||||||
} else {
|
} else {
|
||||||
cleanupTransactions(transactionCleanups, i + 1)
|
cleanupTransactions(transactionCleanups, i + 1)
|
||||||
}
|
}
|
||||||
@@ -360,6 +361,9 @@ export const transact = (doc, f, origin = null, local = true) => {
|
|||||||
initialCall = true
|
initialCall = true
|
||||||
doc._transaction = new Transaction(doc, origin, local)
|
doc._transaction = new Transaction(doc, origin, local)
|
||||||
transactionCleanups.push(doc._transaction)
|
transactionCleanups.push(doc._transaction)
|
||||||
|
if (transactionCleanups.length === 1) {
|
||||||
|
doc.emit('beforeAllTransactions', [doc])
|
||||||
|
}
|
||||||
doc.emit('beforeTransaction', [doc._transaction, doc])
|
doc.emit('beforeTransaction', [doc._transaction, doc])
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ export const testFormattingRemovedInMidText = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testInsertAndDeleteAtRandomPositions = tc => {
|
export const testInsertAndDeleteAtRandomPositions = tc => {
|
||||||
const N = 10000
|
const N = 100000
|
||||||
const { text0 } = init(tc, { users: 1 })
|
const { text0 } = init(tc, { users: 1 })
|
||||||
const gen = tc.prng
|
const gen = tc.prng
|
||||||
|
|
||||||
@@ -293,7 +293,7 @@ const tryGc = () => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testLargeFragmentedDocument = tc => {
|
export const testLargeFragmentedDocument = tc => {
|
||||||
const itemsToInsert = 2000000
|
const itemsToInsert = 1000000
|
||||||
let update = /** @type {any} */ (null)
|
let update = /** @type {any} */ (null)
|
||||||
;(() => {
|
;(() => {
|
||||||
const doc1 = new Y.Doc()
|
const doc1 = new Y.Doc()
|
||||||
|
|||||||
Reference in New Issue
Block a user