Skip to content

Commit

Permalink
feat(relaunch-data): cleanup relaunch data
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed May 1, 2020
1 parent 52a6073 commit 427a1d5
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function main() {
await figma.clientStorage.setAsync('id', instanceId);
}

if(!roomName && !secret) {
if (!roomName && !secret) {
figma.root.setPluginData('ownerId', instanceId);
}

Expand All @@ -52,9 +52,6 @@ async function main() {
figma.root.setPluginData('history', history);
}




return {
roomName,
secret,
Expand Down Expand Up @@ -115,18 +112,32 @@ function iterateOverFile(node, cb) {
}
}

let previousSelection = figma.currentPage.selection || [];

main().then(({ roomName, secret, history, instanceId }) => {
postMessage('ready');

// events
figma.on('selectionchange', () => {
iterateOverFile(figma.root, (node) => {
if (node.setRelaunchData && isValidShape(node)) {
node.setRelaunchData({
relaunch: '',
});
if (figma.currentPage.selection.length > 0) {
for (let node of figma.currentPage.selection) {
if (node.setRelaunchData && isValidShape(node)) {
node.setRelaunchData({
relaunch: '',
});
}
}
});
previousSelection = figma.currentPage.selection;
} else {
if (previousSelection.length > 0) {
// tidy up 🧹
for (let node of previousSelection) {
if (node.setRelaunchData && isValidShape(node)) {
node.setRelaunchData({});
}
}
}
}
if (triggerSelectionEvent) {
sendSelection();
}
Expand Down

0 comments on commit 427a1d5

Please sign in to comment.