Skip to content

Advanced: Trees example from README throws TypError: Cannot read properties of undefined (reading 'push') #65

@mtmacdonald

Description

@mtmacdonald

Hi! I tried to follow the Advanced: Trees example from the README, both in my project and directly in the test suite of this repo. Specifically this codeblock:

const node = schema.LoroMap({ name: schema.String({ required: true }) });
const s = schema({ tree: schema.LoroTree(node) });
const mirror = new Mirror({ doc: new LoroDoc(), schema: s });

mirror.setState((st) => {
    st.tree.push({ data: { name: "root" }, children: [] });
});

When I add a unit test to run it (e.g. in schema-any.test.ts in this repo):

    it("schema.LoroTree example from docs, Cannot read properties of undefined (reading 'push')", async () => {
        const node = schema.LoroMap({
            name: schema.String({ required: true }),
        });
        const s = schema({ tree: schema.LoroTree(node) });
        const mirror = new Mirror({ doc: new LoroDoc(), schema: s });

        mirror.setState((st) => {
            st.tree.push({ data: { name: "root" }, children: [] });
        });
    });

I get an exception: TypeError: Cannot read properties of undefined (reading 'push')

I have not succeeded in using schema.LoroTree in my project. Would you please be able to help debug/fix this, and/or update the docs with a working example of how to use schema.LoroTree? Thank you!

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions