Compare commits

..

10 Commits

Author SHA1 Message Date
Kevin Jahns
ce3b0f3043 13.3.2 2020-08-07 19:31:29 +02:00
Kevin Jahns
94646b2f45 fix item.content undefined 2020-08-07 19:29:08 +02:00
Kevin Jahns
29c2ad4492 13.3.1 2020-08-07 17:53:00 +02:00
Kevin Jahns
637fadf38e lint markdown 2020-08-07 17:51:17 +02:00
Kevin Jahns
0c6c11d583 Merge branch 'main' of github.com:yjs/yjs into main 2020-08-07 17:47:28 +02:00
Kevin Jahns
6f9a2c9df7 implement before/afterAllTransactions 2020-08-07 17:47:20 +02:00
Kevin Jahns
7876a96163 Merge pull request #224 from ajhyndman/document-tojson
Document the  doc.toJSON method
2020-08-04 16:53:10 +02:00
Andrew Hyndman
22653c799c Document the doc.toJSON method 2020-07-22 21:47:55 -07:00
Kevin Jahns
68109b033f lint - fixes #223 2020-07-22 12:32:34 +02:00
Kevin Jahns
38eb2e502c stricter searchMarker filter 2020-07-16 20:44:54 +02:00
7 changed files with 24 additions and 9 deletions

View File

@@ -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>
parameter that is stored on <code>transaction.origin</code> and
<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>
<b><code>get(string, Y.[TypeClass]):[Type]</code></b>
<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>
<b><code>on('afterTransaction', function(Y.Transaction, Y.Doc):void)</code></b>
<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&lt;Y.Transaction&gt;):void)</code></b>
<dd>Emitted after the last transaction is cleaned up.</dd>
</dl>
### Document Updates

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.3.0",
"version": "13.3.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.3.0",
"version": "13.3.2",
"description": "Shared Editing Library",
"main": "./dist/yjs.cjs",
"module": "./dist/yjs.mjs",

View File

@@ -11,7 +11,7 @@ import {
ContentAny,
ContentBinary,
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'
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 math from 'lib0/math.js'
const maxSearchMarker = 60
const maxSearchMarker = 80
/**
* A unique timestamp that identifies each marker.
@@ -152,11 +152,12 @@ export const findMarker = (yarray, index) => {
// if (marker) {
// if (window.lengthes == null) {
// window.lengthes = []
// window.getLengthes = () => window.lengthes.sort((a, b) => a - b)
// }
// window.lengthes.push(marker.index - pindex)
// 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
overwriteMarker(marker, p, pindex)
return marker

View File

@@ -782,8 +782,7 @@ export class YText extends AbstractType {
continue
}
iterateStructs(transaction, /** @type {Array<Item|GC>} */ (doc.store.clients.get(client)), clock, afterClock, item => {
// @ts-ignore
if (item.content.constructor === ContentFormat) {
if (!item.deleted && /** @type {Item} */ (item).content.constructor === ContentFormat) {
foundFormattingItem = true
}
})

View File

@@ -337,6 +337,7 @@ const cleanupTransactions = (transactionCleanups, i) => {
}
if (transactionCleanups.length <= i + 1) {
doc._transactionCleanups = []
doc.emit('afterAllTransactions', [doc, transactionCleanups])
} else {
cleanupTransactions(transactionCleanups, i + 1)
}
@@ -360,6 +361,9 @@ export const transact = (doc, f, origin = null, local = true) => {
initialCall = true
doc._transaction = new Transaction(doc, origin, local)
transactionCleanups.push(doc._transaction)
if (transactionCleanups.length === 1) {
doc.emit('beforeAllTransactions', [doc])
}
doc.emit('beforeTransaction', [doc._transaction, doc])
}
try {

View File

@@ -209,7 +209,7 @@ export const testFormattingRemovedInMidText = tc => {
* @param {t.TestCase} tc
*/
export const testInsertAndDeleteAtRandomPositions = tc => {
const N = 10000
const N = 100000
const { text0 } = init(tc, { users: 1 })
const gen = tc.prng
@@ -293,7 +293,7 @@ const tryGc = () => {
* @param {t.TestCase} tc
*/
export const testLargeFragmentedDocument = tc => {
const itemsToInsert = 2000000
const itemsToInsert = 1000000
let update = /** @type {any} */ (null)
;(() => {
const doc1 = new Y.Doc()