GithubHelp home page GithubHelp logo

[LORO-369] Simplify Tree about loro HOT 2 CLOSED

zxch3n avatar zxch3n commented on June 16, 2024 1
[LORO-369] Simplify Tree

from loro.

Comments (2)

joakim avatar joakim commented on June 16, 2024 2

I read on Discord that you'd like some feedback on the Tree API.

Here's how I would prefer to work with trees:

const doc = new Loro();

// ... load from persistence ...

const root = doc.getTree('root') // LoroTree

// 'data' instead of 'meta', as a getter?
root.data.set('foo', 123);

// create a child directly on the parent (returns the child node)
const child = root.createNode(); // LoroTree
child.data.set('bar', true);

// create child of child
const child2 = child.createNode();

// move to other node (append if ordered)
child2.moveTo(root) // argument: LoroTree

// move before/after other node (anywhere in the tree)
child2.moveBefore(child) // argument: LoroTree
child2.moveAfter(child)

// reorder children just the same
child.moveAfter(child2)

// get all children
console.log(root.children) // LoroTree[child2, child]

assertEquals(child.parent, child2.parent)
assertEquals(root.children[0], child2)
assertEquals(root.lastChild, child)

// delete node
child2.delete()

from loro.

zxch3n avatar zxch3n commented on June 16, 2024

Done

from loro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.