versatile-tree
Advanced tools
Comparing version 1.2.1 to 1.3.1
@@ -63,2 +63,11 @@ /** | ||
/** | ||
* Sets the data for this node. By default, the children property is ignored. | ||
* | ||
* To replace children, pass the `replaceChildren` argument value as `true`. | ||
* | ||
* @param newData The new data for this node. | ||
* @param replaceChildren Optional. When true, children of the node will be replaced with the children in the data. When false, the children property is ignored and only the node's data is set. Default false. | ||
*/ | ||
setData(newData: Record<string, any>, replaceChildren?: boolean): void; | ||
/** | ||
* Returns the property name used for children. | ||
@@ -65,0 +74,0 @@ * |
@@ -80,2 +80,27 @@ "use strict"; | ||
/** | ||
* Sets the data for this node. By default, the children property is ignored. | ||
* | ||
* To replace children, pass the `replaceChildren` argument value as `true`. | ||
* | ||
* @param newData The new data for this node. | ||
* @param replaceChildren Optional. When true, children of the node will be replaced with the children in the data. When false, the children property is ignored and only the node's data is set. Default false. | ||
*/ | ||
setData(newData, replaceChildren = false) { | ||
var _a; | ||
const newDataWithoutChildren = Object.assign({}, newData); | ||
delete newDataWithoutChildren[this.childrenPropertyName]; | ||
this.data = newData; | ||
if (replaceChildren) { | ||
const childrenData = (_a = newData[this.childrenPropertyName]) !== null && _a !== void 0 ? _a : []; | ||
const childrenDataIsArray = Array.isArray(childrenData); | ||
this.children = []; | ||
if (childrenDataIsArray) { | ||
childrenData.forEach((childData) => this.addChildNode(new TreeNode(childData, this.options))); | ||
} | ||
else { | ||
console.error(`TreeNode: Expected children property "${this.childrenPropertyName}" to be an array of children data. Instead got ${typeof childrenData}:`, childrenData); | ||
} | ||
} | ||
} | ||
/** | ||
* Returns the property name used for children. | ||
@@ -82,0 +107,0 @@ * |
{ | ||
"name": "versatile-tree", | ||
"version": "1.2.1", | ||
"version": "1.3.1", | ||
"author": "Justin Mahar <contact@justinmahar.com>", | ||
@@ -5,0 +5,0 @@ "description": "A highly versatile tree structure for JavaScript.", |
@@ -74,2 +74,3 @@ <h2 align="center"> | ||
- [getData](#getdata) | ||
- [setData](#setdata) | ||
- [getChildrenPropertyName](#getchildrenpropertyname) | ||
@@ -206,2 +207,19 @@ - [hasParent](#hasparent) | ||
#### setData | ||
```ts | ||
setData(newData: Record<string, any>, replaceChildren = false) | ||
``` | ||
Sets the data for this node. By default, the children property is ignored. | ||
To replace children, pass the `replaceChildren` argument value as `true`. | ||
| Param | Description | | ||
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `newData` | The new data for this node. | | ||
| `replaceChildren` | Optional. When true, children of the node will be replaced with the children in the data. When false, the children property is ignored and only the node's data is set. Default false. | | ||
--- | ||
#### getChildrenPropertyName | ||
@@ -208,0 +226,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181162
1422
1034