MCPcopy
hub / github.com/yjs/yjs / toArray

Method toArray

src/ytype.js:1266–1280  ·  view source on GitHub ↗

* @todo refactor this, this should use getContent only! * * Transforms this YArray to a JavaScript Array. * * @return {Array | delta.DeltaConfGetText >}

()

Source from the content-addressed store, hash-verified

1264 * @return {Array<delta.DeltaConfGetChildren<DConf> | delta.DeltaConfGetText<DConf>>}
1265 */
1266 toArray () {
1267 const dcontent = this.toDelta()
1268 /**
1269 * @type {Array<any>}
1270 */
1271 const children = []
1272 for (const child of dcontent.children) {
1273 if (delta.$insertOp.check(child)) {
1274 children.push(...child.insert)
1275 } else if (delta.$textOp.check(child)) {
1276 children.push(child.insert)
1277 }
1278 }
1279 return children
1280 }
1281
1282 /**
1283 * Transforms this Shared Type to a JSON object.

Callers 15

toJSONMethod · 0.95
toStringMethod · 0.95
mapMethod · 0.95
forEachMethod · 0.95
testBasicUpdateFunction · 0.80
testArrayFromFunction · 0.80
testLengthIssueFunction · 0.80
testLengthIssue2Function · 0.80
testNestedObserverEventsFunction · 0.80
y-array.tests.jsFile · 0.80
compareFunction · 0.80

Calls 2

toDeltaMethod · 0.95
pushMethod · 0.80

Tested by

no test coverage detected