* Perform an action against the layout tree state. * @param action The action to perform.
(action: LayoutTreeAction, setState = true)
| 613 | * @param action The action to perform. |
| 614 | */ |
| 615 | treeReducer(action: LayoutTreeAction, setState = true) { |
| 616 | switch (action.type) { |
| 617 | case LayoutTreeActionType.ComputeMove: |
| 618 | this.setter( |
| 619 | this.pendingTreeAction.throttledValueAtom, |
| 620 | computeMoveNode(this.treeState, action as LayoutTreeComputeMoveNodeAction) |
| 621 | ); |
| 622 | break; |
| 623 | case LayoutTreeActionType.Move: |
| 624 | moveNode(this.treeState, action as LayoutTreeMoveNodeAction); |
| 625 | break; |
| 626 | case LayoutTreeActionType.InsertNode: |
| 627 | insertNode(this.treeState, action as LayoutTreeInsertNodeAction); |
| 628 | if ((action as LayoutTreeInsertNodeAction).focused) { |
| 629 | FocusManager.getInstance().requestNodeFocus(); |
| 630 | } |
| 631 | break; |
| 632 | case LayoutTreeActionType.InsertNodeAtIndex: |
| 633 | insertNodeAtIndex(this.treeState, action as LayoutTreeInsertNodeAtIndexAction); |
| 634 | if ((action as LayoutTreeInsertNodeAtIndexAction).focused) { |
| 635 | FocusManager.getInstance().requestNodeFocus(); |
| 636 | } |
| 637 | break; |
| 638 | case LayoutTreeActionType.DeleteNode: |
| 639 | deleteNode(this.treeState, action as LayoutTreeDeleteNodeAction); |
| 640 | break; |
| 641 | case LayoutTreeActionType.Swap: |
| 642 | swapNode(this.treeState, action as LayoutTreeSwapNodeAction); |
| 643 | break; |
| 644 | case LayoutTreeActionType.ResizeNode: |
| 645 | resizeNode(this.treeState, action as LayoutTreeResizeNodeAction); |
| 646 | break; |
| 647 | case LayoutTreeActionType.SetPendingAction: { |
| 648 | const pendingAction = (action as LayoutTreeSetPendingAction).action; |
| 649 | if (pendingAction) { |
| 650 | this.setter(this.pendingTreeAction.throttledValueAtom, pendingAction); |
| 651 | } else { |
| 652 | console.warn("No new pending action provided"); |
| 653 | } |
| 654 | break; |
| 655 | } |
| 656 | case LayoutTreeActionType.ClearPendingAction: |
| 657 | this.setter(this.pendingTreeAction.throttledValueAtom, undefined); |
| 658 | break; |
| 659 | case LayoutTreeActionType.CommitPendingAction: { |
| 660 | const pendingAction = this.getter(this.pendingTreeAction.currentValueAtom); |
| 661 | if (!pendingAction) { |
| 662 | console.error("unable to commit pending action, does not exist"); |
| 663 | break; |
| 664 | } |
| 665 | this.treeReducer(pendingAction); |
| 666 | this.setter(this.pendingTreeAction.throttledValueAtom, undefined); |
| 667 | break; |
| 668 | } |
| 669 | case LayoutTreeActionType.FocusNode: |
| 670 | focusNode(this.treeState, action as LayoutTreeFocusNodeAction); |
| 671 | FocusManager.getInstance().requestNodeFocus(); |
| 672 | break; |
no test coverage detected