Members
(constant) lodash
Example usage: const { createDataTree } = require("./dataTree"); const unmount = createDataTree(template, props, emitCallback); // ... unmount(); // gracefully unmounts everything
Methods
applyDefaults(templateopt) → {Object}
Applies defaults to a given template without mutating it.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
template |
Object |
<optional> |
{}
|
The template object. |
Returns:
- A shallow copy of the template with default methods.
- Type
- Object
areNodesEqual(prev, next) → {boolean}
Compares two node structures by checking their templates and props.
Parameters:
Name | Type | Description |
---|---|---|
prev |
Object | The previous node object. |
next |
Object | The next node object. |
Returns:
- True if nodes are considered equal, false otherwise.
- Type
- boolean
copyTree(map, path, includeParent) → {SortedMap}
Copies a portion of the map for the specified path.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
map |
SortedMap | The map containing DOM nodes. |
|
path |
Array | The path array used to determine range. |
|
includeParent |
boolean |
false
|
Whether to include the parent in the copy. |
Returns:
- A copy of the map subset.
- Type
- SortedMap
createDataTree(template, props, emit, domopt) → {function}
Primary function that manages a data-driven tree structure with lifecycle events.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
template |
Object | The root template, typically a function node. |
||
props |
any | The props passed to the root template. |
||
emit |
function | Callback to handle data changes. |
||
dom |
SortedMap |
<optional> |
SortedMap()
|
Optional existing DOM map. |
Returns:
- Unmount function that cleans up root and all children.
- Type
- function
createNodeFactory(cb) → {function}
Main factory that creates node instances with standardized lifecycle.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | Callback triggered after rendering a node. |
Returns:
- A function that accepts a path array and returns a node creator.
- Type
- function
createPathDeduplicator() → {function}
Creates a deduplicator to track if a path has been processed.
Returns:
- Accepts a path array, returns true if it's a duplicate.
- Type
- function
getMd5(str) → {string}
Creates an MD5 hash of the given string or value.
Parameters:
Name | Type | Description |
---|---|---|
str |
any | The string or value to hash. |
Returns:
- The MD5 hash as a hex string.
- Type
- string
initializeChild(template, parentPath) → {function}
Creates a dedicated path-based child initializer function.
Parameters:
Name | Type | Description |
---|---|---|
template |
Object | The template object for the child. |
parentPath |
Array | The path leading to the child. |
Returns:
- A function that returns [template, props].
- Type
- function
initializeNode(init) → {Object}
Initializes a node by invoking its function to obtain template and props.
Parameters:
Name | Type | Description |
---|---|---|
init |
Object | The object containing value function, path, etc. |
Returns:
- Updated init object with template and props fields.
- Type
- Object
makeId(path) → {string}
Creates an ID from a path.
Parameters:
Name | Type | Description |
---|---|---|
path |
Array | Array of path segments. |
Returns:
- String representation of path, with ~ appended.
- Type
- string
mountDataNode(init) → {Object}
Mounts a node by creating a new instance via createNode and calling its mount method.
Parameters:
Name | Type | Description |
---|---|---|
init |
Object | Object containing path, template, and props. |
Returns:
- Updated node with an unmount function.
- Type
- Object
processNodeRender(dom, emit, path, data)
Main callback function to process node rendering. This handles tree diffing, unmounting, and event emissions.
Parameters:
Name | Type | Description |
---|---|---|
dom |
SortedMap | The current DOM-like map of nodes. |
emit |
function | The function to call on data changes. |
path |
Array | The path leading to the node being rendered. |
data |
any | The new data for the node. |
unmountChildren(map, path, includeParent, reason)
Unmounts children of a particular node subtree.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
map |
SortedMap | The DOM map. |
|
path |
Array | The path to the node. |
|
includeParent |
boolean |
true
|
If true, unmount the parent as well. |
reason |
string | Optional reason for unmounting. |