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

Extra content when add components in onRender #9

Open
longdoan7421 opened this issue Dec 27, 2019 · 0 comments
Open

Extra content when add components in onRender #9

longdoan7421 opened this issue Dec 27, 2019 · 0 comments

Comments

@longdoan7421
Copy link

longdoan7421 commented Dec 27, 2019

Hi @artf,

Currently, I have to add some small components dynamically after user changes trait (eg: rewind, infinity, ...). My solution was add those by using onRender() method in Slider component. but the issue is when the Slider component re-render, it has extra components.

Here is a simple demo (for simplicity, I reset all components then add new ones):
grapesjs-lory-slider

And this is my change in view of Slider component:

view: defaultView.extend({
      init() {
        const props = [
          'rewind'
        ];
        const reactTo = props.map(prop => `change:${prop}`).join(' ');
        this.listenTo(this.model, reactTo, this.render);
        const comps = this.model.components();

        // Add a basic template if it's not yet initialized
        if (!comps.length) {
          comps.add(`<div data-gjs-type="${frameName}">
              <div data-gjs-type="${slidesName}">${config.slideEls}</div>
          </div>
          <span data-gjs-type="${prevName}">${config.prevEl}</span>
          <span data-gjs-type="${nextName}">${config.nextEl}</span>`);
        }
      },

      onRender() {
        console.log('onRender', index);
        if (index == 0) {
          // ignore first render
        } else {
          const comps = this.model.components();
          // comps.reset();
          comps.add(`<h1>Text ${index}</h1>`);
        }

        index++;
      }
})

I hope you have some solutions about this, thank you and happy holiday :D

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

1 participant