Skip to content

LoroTree toJSON uses meta key where data would make more sense #891

@canadaduane

Description

@canadaduane

When working with LoroTree, the API uses node.data to access the node's LoroMap, but toJSON() outputs this as meta:

Example

import { LoroDoc } from "loro-crdt"

const doc = new LoroDoc()
const tree = doc.getTree("tree")

// Create a node
const node = tree.createNode()

// The API uses `.data` to access the node's LoroMap
node.data.set("name", "root")
node.data.set("value", 42)

console.log("API uses .data:", node.data.toJSON())
// Output: { name: "root", value: 42 }

// But toJSON() outputs it as `meta`
console.log("toJSON uses meta:", JSON.stringify(tree.toJSON(), null, 2))

Output:

[
  {
    parent: null,
    index: 0,
    meta: { name: 'root', value: 42 }, <-- "meta" instead of "data"
    id: '0@3781444021239823132',
    fractional_index: '80',
    children: []
  }
]

I think it would be more consistent if the toJSON() output also used data as the key here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions