Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb committed Apr 1, 2024
1 parent e33687c commit 13758b2
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const background = {
},
};

const nodes = new Map<null | number, DebugNode>();
const nodes = {} as { [key: string]: DebugNode };

function resolveEventBubble(node: any) {
if (!node.detail || !node.detail.listeners) return;
Expand Down Expand Up @@ -42,58 +42,66 @@ port.onMessage.addListener(({ type, payload }) => {
case 'bridge::ext/clear': {
selected.set(undefined);
hovered.set(undefined);
return root.set([]);
root.set([]);
break;
}

case 'bridge::ext/inspect': {
if (typeof payload === 'string') return;
const current = nodes.get(payload.node.id);
return selected.set(current);
if (typeof payload === 'string') break;
const current = nodes[payload.node.id];
selected.set(current);
break;
}

case 'bridge::courier/node->add': {
const { node, target, anchor } = payload as {
node: DebugNode;
target: null | number;
anchor: null | number;
target: string;
anchor: string;
};

node.children = [];
node.expanded = false;
node.invalidate = () => {};
resolveEventBubble(node);

const parent = nodes.get(target);
nodes.set(node.id, node);
if (!parent) return root.update((n) => [...n, node]);
const parent = nodes[target];
nodes[node.id] = node;
if (!parent) {
root.update((n) => [...n, node]);
break;
}

const index = parent.children.findIndex((n) => n.id === anchor);
if (index === -1) parent.children.push(node);
else parent.children.splice(index, 0, node);

return (node.parent = parent).invalidate();
(node.parent = parent).invalidate();
break;
}

case 'bridge::courier/node->remove': {
const node = payload.node as SvelteBlockDetail;
const current = nodes.get(node.id);
if (current) nodes.delete(current.id);
if (!current?.parent) return;
const current = nodes[node.id];
if (current) delete nodes[current.id];
if (!current?.parent) break;

const index = current.parent.children.findIndex((o) => o.id === current.id);
current.parent.children.splice(index, 1);
return current.parent.invalidate();
current.parent.invalidate();
break;
}

case 'bridge::courier/node->update': {
const node = payload.node as SvelteBlockDetail;
const current = nodes.get(node.id);
if (!current) return;
const current = nodes[node.id];
if (!current) break;
Object.assign(current, payload.node);
resolveEventBubble(current);

selected.update((o) => o);
return current.invalidate();
current.invalidate();
break;
}

// case 'bridge::courier/profile->update': {
Expand Down

0 comments on commit 13758b2

Please sign in to comment.