Skip to content

Commit

Permalink
refactor: add docs for nodes.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
danferns committed Oct 10, 2023
1 parent 22ea1c4 commit 1471472
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/ts/nodes/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
* along with MIDI-FX. If not, see <https://www.gnu.org/licenses/>.
*/

// 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",
Expand Down Expand Up @@ -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<SvelteComponent> {
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.`;
}
throw `Node '${nodeType}' not found.`;
}

0 comments on commit 1471472

Please sign in to comment.