ObjectTree

Wraps a plain JavaScript object or array as an async tree

Usage

Create a new ObjectTree by passing an object or array to the constructor:

// object.js

import { ObjectTree } from "@weborigami/origami";

// Wrap an object to create an async tree.
export default new ObjectTree({
  Alice: "Hello, Alice.",
  Bob: "Hello, Bob.",
  Carol: "Hello, Carol.",
});

This defines a tree whose keys are the object’s keys, and whose values are the object’s values:

g Alice Hello, Alice. ->Alice Alice Bob Hello, Bob. ->Bob Bob Carol Hello, Carol. ->Carol Carol

The ori tool will display the contents of the resulting ObjectTree.

$ ori object.js/
Alice: Hello, Alice.
Bob: Hello, Bob.
Carol: Hello, Carol.

ObjectTree class

ObjectTree(object) constructor

  • object: any – The object/array to wrap.

Create a tree wrapping a given plain object or array.

async get(key)

  • key: any

Returns: unknown

Return the value for the given key.

async keys()

Returns: unknown

Enumerate the object’s keys.

async set(key, value)

  • key: any
  • value: any

Returns: unknown

Set the value for the given key. If the value is undefined, delete the key.