From 1471472ba23359eeb5dbb503b1260c772c9e774a Mon Sep 17 00:00:00 2001 From: danferns Date: Tue, 10 Oct 2023 17:37:15 +0530 Subject: [PATCH] refactor: add docs for nodes.ts --- src/ts/nodes/nodes.ts | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/ts/nodes/nodes.ts b/src/ts/nodes/nodes.ts index 18ed7f6..2cc9bfa 100644 --- a/src/ts/nodes/nodes.ts +++ b/src/ts/nodes/nodes.ts @@ -17,8 +17,10 @@ * along with MIDI-FX. If not, see . */ -// Defined as per folder structure. +import type { SvelteComponent } from "svelte"; +// A mapping from node-types to their Titles. +// Defined as per folder structure. export const NODES = { io: { "midi-input": "External Input", @@ -50,20 +52,30 @@ export const NODES = { }, }; -export async function importNodeComponent(type: string) { +/** + * Import the Svelte component of a given node. + * @param nodeType the type of node to import. eg. `midi-input`. + * @returns Promise of Svelte component of the node. + */ +export async function importNodeComponent(nodeType: string): Promise { for (const category of Object.keys(NODES)) { - if (Object.keys(NODES[category]).includes(type)) { - return await import(`../../svelte/nodes/${category}/${type}.svelte`); + if (Object.keys(NODES[category]).includes(nodeType)) { + return await import(`../../svelte/nodes/${category}/${nodeType}.svelte`); } } - throw `Node '${type}' not found.`; + throw `Node '${nodeType}' not found.`; } -export function getNodeTitle(type: string) { +/** + * Get the display title string of a node. + * @param nodeType the type of the node. eg. `midi-input`. + * @returns Title of the node + */ +export function getNodeTitle(nodeType: string): string { for (const category of Object.keys(NODES)) { - if (Object.keys(NODES[category]).includes(type)) { - return NODES[category][type]; + if (Object.keys(NODES[category]).includes(nodeType)) { + return NODES[category][nodeType]; } } - throw `Node '${type}' not found.`; -} \ No newline at end of file + throw `Node '${nodeType}' not found.`; +}