chore(useNodesData): cleanup return type

This commit is contained in:
moklick
2024-02-26 14:13:12 +01:00
parent 89a90cb848
commit 3fc3b7e603
6 changed files with 24 additions and 43 deletions
+2 -12
View File
@@ -20,18 +20,8 @@ export interface NodeDataReturn<NodeType extends Node> {
*/
export function useNodesData<NodeType extends Node = Node>(
nodeId: string
): {
id: string;
type: NodeType['type'];
data: NodeType['data'];
} | null;
export function useNodesData<NodeType extends Node = Node>(
nodeIds: string[]
): {
id: string;
type: NodeType['type'];
data: NodeType['data'];
}[];
): Pick<NodeType, 'id' | 'type' | 'data'> | null;
export function useNodesData<NodeType extends Node = Node>(nodeIds: string[]): Pick<NodeType, 'id' | 'type' | 'data'>[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useNodesData(nodeIds: any): any {
const nodesData = useStore(
+3 -15
View File
@@ -22,33 +22,21 @@ function areNodesDataEqual(a: any[], b: any[]) {
*
* @public
* @param nodeId - The id (or ids) of the node to get the data from
* @param guard - Optional guard function to narrow down the node type
* @returns A readable store with an array of data objects
*/
export function useNodesData<NodeType extends Node = Node>(
nodeId: string
): Readable<{
id: string;
type: NodeType['type'];
data: NodeType['data'];
} | null>;
): Readable<Pick<NodeType, 'id' | 'data' | 'type'> | null>;
export function useNodesData<NodeType extends Node = Node>(
nodeIds: string[]
): Readable<
{
id: string;
type: NodeType['type'];
data: NodeType['data'];
}[]
>;
): Readable<Pick<NodeType, 'id' | 'data' | 'type'>[]>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useNodesData(nodeIds: any): any {
const { nodes, nodeLookup } = useStore();
let prevNodesData: any = [];
return derived([nodes, nodeLookup], ([, nodeLookup], set) => {
let nextNodesData = [];
const nextNodesData = [];
const isArrayOfIds = Array.isArray(nodeIds);
const _nodeIds = isArrayOfIds ? nodeIds : [nodeIds];