You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In each cell of my layout I have a component that's very expensive to initialize. I have a list of predefined layouts a user can select from. When they select a new layout I create a new layout model which triggers my components to be unmounted. I want to avoid re-initializing my components by not changing the layout model reference but rather update it. Is this possible?
my current function to create a new model from my predefined layouts:
export const buildLayoutModel = (existingModel: Model | undefined, newJsonLayout: IJsonRowNode) => {
const newModel = Model.fromJson({ ...DEFAULT_LAYOUT_JSON_MODEL, layout: newJsonLayout });
// apply any existing ids from existing model to the new model
const existingIds = new Set<string>();
existingModel?.visitNodes((node) => {
if (node.getType() === 'tabset') {
existingIds.add(node.getId());
}
});
newModel.visitNodes((node) => {
if (node.getType() === 'tabset') {
const nextNodeId = existingIds.values().next().value;
if (nextNodeId) {
node.setId(nextNodeId);
existingIds.delete(nextNodeId);
}
}
});
// Rebuild the model to ensure updates are reflected
return Model.fromJson(newModel.toJson());
};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In each cell of my layout I have a component that's very expensive to initialize. I have a list of predefined layouts a user can select from. When they select a new layout I create a new layout model which triggers my components to be unmounted. I want to avoid re-initializing my components by not changing the layout model reference but rather update it. Is this possible?
my current function to create a new model from my predefined layouts:
Beta Was this translation helpful? Give feedback.
All reactions