i’am trying to link hight of a node with another one and having an option to delete that link and that needs the use of figma.on documentchange but the problem is when deleting the handler by figma.off it dosen’t work i have created an if statement to know the deleting message that have been sent when delete button pressed by adding an id wich is 2
if (pluginMessage.id === 'link-it') {
const lnode = figma.getNodeById(pluginMessage.nodeid);
const node = figma.getNodeById(pluginMessage.keysids);
const id = node?.id as string + lnode?.id as string
let fn = (event: { documentChanges: any; }) =>{
for (const change of event.documentChanges) {
if (change.type === 'PROPERTY_CHANGE') {
if (change.id === node?.id) {
lnode.resize(lnode.width, node.height)
}
}
}
}
if (pluginMessage.subid !== 2) {
//add links into the storage
figma.clientStorage.setAsync(id,{subid:'linked',node:node?.id as string,link:lnode?.id});
//do the height changes in figma and post message of the id of nodes to the frontend to put the new links
lnode.resize(lnode.width, node.height)
figma.ui.postMessage({node:node?.id, link:lnode?.id, id:'storageadd',subid:'link'})
//if node height changes change it in the linked node
figma.on('documentchange', fn)
}
else if (pluginMessage.subid === 2) {
figma.clientStorage.deleteAsync(pluginMessage.delnode)
figma.off('documentchange', fn)
}
}