Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update properties without destroying and reinitialization? #765

Open
faizananwerali opened this issue Nov 18, 2022 · 1 comment
Open

Comments

@faizananwerali
Copy link

How to update properties without destroying and reinitialization?

  async initSplitInstance() {
    if (this.rightLeftSplitInstance) {
      this.rightLeftSplitInstance.destroy(true);
    }
    setTimeout(() => {
      this.rightLeftSplitInstance = Split([this.leftPanel.nativeElement, this.rightPanel.nativeElement], {
        sizes: [75, 25],
        minSize: [300, 300],
        expandToMin: true,
        // gutterSize: 5,
        // cursor: 'col-resize',
        direction: this.selectedLayout === EditorLayouts.LEFT || this.selectedLayout === EditorLayouts.RIGHT ? 'horizontal' : 'vertical',
        elementStyle: function (dimension, size, gutterSize) {
          return {
            'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)',
          }
        },
        gutter(index: number, direction: "horizontal" | "vertical"): HTMLElement {
          const gutter = document.createElement('div');
          gutter.className = `gutter gutter-${direction}`;
          return gutter;
        },
        gutterStyle: function (dimension, gutterSize) {
          return {
            'flex-basis': gutterSize + 'px',
          }
        },
        onDrag: () => {
          this.isDragging = true;
        },
        onDragEnd: () => {
          this.isDragging = false;
        }
      });
    }, 0);
  }

In this example, the this.selectedLayout is EditorLayouts.RIGHT so the direction is horizontal.

In HTML this is how I have implemented it.

<div class="relative h-full flex split-box" [ngClass]="{
        'flex-row': selectedLayout === EditorLayoutsEnum.RIGHT,
        'flex-row-reverse': selectedLayout === EditorLayoutsEnum.LEFT,
        'flex-col': selectedLayout === EditorLayoutsEnum.BOTTOM,
        'flex-col-reverse': selectedLayout === EditorLayoutsEnum.TOP
       }">
       ...
</div>

Now, whenever the user presses any of these change layout buttons. I have to destroy the instance and reinitialize the Split.js.
image

  changeLayout($event: MouseEvent, layout: EditorLayouts) {
    this.selectedLayout = layout;
    this.initSplitInstance();
  }

Is there a way to do this more efficiently? maybe not destroying the instance, just update it?

@firstdorsal
Copy link

Did you manage to figure out a better way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants