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

Nested map (for cells in a grid) #35

Closed
sekoyo opened this issue Jan 7, 2021 · 3 comments
Closed

Nested map (for cells in a grid) #35

sekoyo opened this issue Jan 7, 2021 · 3 comments

Comments

@sekoyo
Copy link

sekoyo commented Jan 7, 2021

Hey thanks for the lib looks sweet. I'm checking I have the syntax here right (guessing not) as it throws on subsequent renders after the first one:

  render = () => {
    console.log(this._columnRange); // [0, 1]
    console.log(this._rowRange); // [0, 1, 2, 3, 4, 5, 6, 7]

    const canvas = html`
      <div class="canvas" style=${`width:${this._canvasWidth}px;height:${this._canvasHeight}px`}>
        ${this._rowRange.map(
          rowIndex =>
            html.node`${this._columnRange.map(columnIndex => {
              return html`<div>cell</div>`;
            })}`
        )}
      </div>
    `;

    render(this._root, canvas);
  };

This is to render a range of cells in a virtual window, and the second render has the same range values. On the second render it throws the following error:

Screenshot 2021-01-07 at 23 22 44

Where am I going wrong here? Also I see perf seems to be about the same with non-keyed items on https://github.com/krausest/js-framework-benchmark which is cool, but not sure how it's being done e.g. maybe the html strings need to be unique? (which they would be once I add the styles to them). Thanks

@WebReflection
Copy link
Owner

html.node creates a new node each time, but moreover, it doesn't understand arrays ... why are you using it at all, if I might ask?

@WebReflection
Copy link
Owner

in few words, I think you want to rather do this:

render = () => {
  console.log(this._columnRange); // [0, 1]
  console.log(this._rowRange); // [0, 1, 2, 3, 4, 5, 6, 7]

  const canvas = html`
    <div class="canvas" style=${`width:${this._canvasWidth}px;height:${this._canvasHeight}px`}>
      ${this._rowRange.map(
        rowIndex =>
          html`<div>${
            this._columnRange.map(columnIndex => html`<div>cell</div>`
          )}</div>`
      )}
    </div>
  `;

  render(this._root, canvas);
};

or you gotta explain me what you are trying to do ... but in any case, html.node is not meant to be used at all in your case, it's either html.for(...) or just html (recommended).

@sekoyo
Copy link
Author

sekoyo commented Jan 7, 2021

Whoops that was it, I had it left over from when I hadn't wrapped it in <div class="canvas"> thanks

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