Is their a way to reset all properties on a group and it's children to default values? Or clone() a Node without causing duplicates to be added to the stage? #1200
-
Here's what I have tried right now: cacheOutOfViewportCells() {
this.cellsMap.forEach((cell, cellId) => {
if (!cell.group.isClientRectOnScreen()) {
cell.text.setAttrs({
...this.cachedCellText.getAttrs(),
});
cell.rect.setAttrs({
...this.cachedCellRect.getAttrs(),
});
this.cachedCellsGroups.push(cell.group);
}
});
} So in the above code I am trying to just reset the attrs of The alternative would be to Basically I am looking for something like this: I also thought of using the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Here's what I did in meantime:
But I think default properties object would be easier than individually doing the above many times |
Beta Was this translation helpful? Give feedback.
-
@magicienap are there issues with the first approach? cell.text.setAttrs({
...this.cachedCellText.getAttrs(),
}); Currently, there is no simple API to reset to defaults. Only if you do that manually. Some options are: // (1) set all to nulls (it will reset to defaults
const oldAttrs = node.getAttrs();
const resetValues = {};
for (var key in oldAttrs) {
resetValues[key] = null;
}
node.setAttrs(resetValues);
// (2) probably this will work too:
node.attrs = {};
node._clearCache(); |
Beta Was this translation helpful? Give feedback.
@magicienap are there issues with the first approach?
Currently, there is no simple API to reset to defaults. Only if you do that manually. Some options are: