feat(svelte): add getInternalNode and useInternalNode

This commit is contained in:
moklick
2024-05-02 16:39:57 +02:00
parent f2f2c3cc2e
commit 534db656b4
4 changed files with 39 additions and 9 deletions
@@ -0,0 +1,17 @@
import { derived, type Readable } from 'svelte/store';
import { useStore } from '$lib/store';
import type { InternalNode } from '$lib/types';
/**
* Hook to get an internal node by id.
*
* @public
* @param id - the node id
* @returns a readable with an internal node or undefined
*/
export function useInternalNode(id: string): Readable<InternalNode | undefined> {
const { nodeLookup, nodes } = useStore();
return derived([nodeLookup, nodes], ([nodeLookup]) => nodeLookup.get(id));
}