import { ActionHandleStrategy } from '../action-handle-strategy.abstract';
/**
 * Append new block array or node array to block or VegaRTEContent instance strategy.
 */
export class AppendChildrenStrategy extends ActionHandleStrategy {
  /**
   * @inheritDoc
   */
  handleAction(action, target) {
    const newBlocks = action.entityToBeAppended;
    if (target.children) {
      newBlocks.forEach((block) => {
        block.parent = target;
      });
      // This line is used to fix the typescript error `This expression is not callable`. https://github.com/microsoft/TypeScript/issues/44373
      const arrayFixed = target.children;
      target.children = arrayFixed.concat(newBlocks);
    }
  }
}
