runem / lit-analyzer

Monorepository for tools that analyze lit-html templates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow ?disabled to be set to AsyncDirective

nmattia opened this issue · comments

It looks like lit-analyzer disallows setting ?disabled to an async directive. It will throw no-invalid-directive-binding:

    The 'asyncReplace' directive can only be used within a text binding.
    56:  ?disabled=${asyncReplace(shouldDisable)}
    no-invalid-directive-binding

In practice lit (and lit-html) do not seem to have an issue with this, as shown by this playground example:

import {html, LitElement} from 'lit';
import {customElement} from 'lit/decorators.js';
import {asyncReplace} from 'lit/directives/async-replace.js';

async function *toggle() {
  let value = false;
  while (true) {
    yield value;
    value = !value;
    await new Promise(resolve => setTimeout(resolve, 1000));
  }
}

@customElement('toggle-button')
export class Toggle extends LitElement {
  render() {
    return html`<button ?disabled=${asyncReplace(toggle())}>click me</button>`;
  }
}

out

This is a great issue. I can definitely investigate this!