Efficient tree and linked list data structure using ES6 Symbols for DOM tree backing
—
Object initialization and SymbolTree instance creation for optimal performance.
Creates a new SymbolTree instance with an optional description for the internal Symbol.
/**
* Create a new SymbolTree instance
* @param {string} [description='SymbolTree data'] - Description used for the internal Symbol
*/
class SymbolTree {
constructor(description?: string);
}Usage Examples:
const SymbolTree = require("symbol-tree");
// Create with default description
const tree = new SymbolTree();
// Create with custom description for debugging
const domTree = new SymbolTree("DOM tree data");Initialize an object right after creation to take advantage of V8's fast properties and enable object freezing.
/**
* Initialize an object for tree operations (optional performance optimization)
* Time Complexity: O(1)
* @param {Object} object - Object to initialize
* @returns {Object} The same object that was passed in
*/
initialize(object: Object): Object;Usage Examples:
const tree = new SymbolTree();
// Basic initialization
const node = tree.initialize({ id: "node1", data: "value" });
// Initialize before freezing (common pattern)
const frozenNode = Object.freeze(
tree.initialize({ id: "node2", readonly: true })
);
// Initialize immediately after creation
class DOMNode {
constructor(tagName) {
this.tagName = tagName;
tree.initialize(this); // Optimize for tree operations
}
}Performance Notes:
initialize() is optional but recommended for objects that will be heavily used in tree operationsInstall with Tessl CLI
npx tessl i tessl/npm-symbol-tree