compose.ts 535 B

123456789101112131415161718
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { FlowNodeEntity } from '@flowgram.ai/editor';
  6. export type ComposeListItem<T> = (node: FlowNodeEntity, data: T[]) => T[];
  7. export const compose =
  8. <T>(fnList: (ComposeListItem<T> | undefined)[]) =>
  9. (node: FlowNodeEntity, data: T[]): T[] => {
  10. const list = fnList.filter(Boolean) as ComposeListItem<T>[];
  11. if (!list.length) {
  12. return data;
  13. }
  14. return list.reduce((acc: T[], fn) => fn(node, acc), data);
  15. };