MCPcopy
hub / github.com/yjs/yjs / readContent

Method readContent

src/utils/AttributionManager.js:515–547  ·  view source on GitHub ↗

* @param {Array >} contents - where to write the result * @param {number} client * @param {number} clock * @param {boolean} deleted * @param {AbstractContent} _content * @param {0|1|2} shouldRender - whether this should render or just result in a `retain` operati

(contents, client, clock, deleted, _content, shouldRender)

Source from the content-addressed store, hash-verified

513 * @param {0|1|2} shouldRender - whether this should render or just result in a `retain` operation
514 */
515 readContent (contents, client, clock, deleted, _content, shouldRender) {
516 const slice = (deleted ? this.deletes : this.inserts).slice(client, clock, _content.getLength())
517 /**
518 * @type {AbstractContent?}
519 */
520 let content = slice.length === 1 ? _content : _content.copy()
521 for (let i = 0; i < slice.length; i++) {
522 const s = slice[i]
523 if (content == null || content instanceof ContentDeleted) {
524 if ((!shouldRender && s.attrs == null) || this.inserts.has(client, s.clock)) {
525 continue
526 }
527 // Retrieved item is never more fragmented than the newer item.
528 const prevItem = getItem(this._prevDocStore, createID(client, s.clock))
529 const diffStart = s.clock - prevItem.id.clock
530 content = prevItem.length > 1 ? prevItem.content.copy() : prevItem.content
531 // trim itemContent to the correct size.
532 if (diffStart > 0) {
533 content = content.splice(diffStart)
534 }
535 }
536 const c = /** @type {AbstractContent} */ (content)
537 const clen = c.getLength()
538 if (clen < s.len) {
539 slice.splice(i + 1, 0, createMaybeAttrRange(s.clock + clen, s.len - clen, s.attrs))
540 s.len = clen
541 }
542 content = s.len < clen ? c.splice(s.len) : null
543 if (shouldRender || !deleted || s.attrs != null) {
544 contents.push(new AttributedContent(c, s.clock, deleted, s.attrs, shouldRender))
545 }
546 }
547 }
548
549 /**
550 * @param {Item} item

Callers 1

contentLengthMethod · 0.95

Calls 8

createIDFunction · 0.90
createMaybeAttrRangeFunction · 0.90
pushMethod · 0.80
sliceMethod · 0.45
getLengthMethod · 0.45
copyMethod · 0.45
hasMethod · 0.45
spliceMethod · 0.45

Tested by

no test coverage detected