live.d.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @license
  3. * Copyright 2020 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. import { AttributePart } from '../lit-html.js';
  7. import { Directive, DirectiveParameters, PartInfo } from '../directive.js';
  8. declare class LiveDirective extends Directive {
  9. constructor(partInfo: PartInfo);
  10. render(value: unknown): unknown;
  11. update(part: AttributePart, [value]: DirectiveParameters<this>): unknown;
  12. }
  13. /**
  14. * Checks binding values against live DOM values, instead of previously bound
  15. * values, when determining whether to update the value.
  16. *
  17. * This is useful for cases where the DOM value may change from outside of
  18. * lit-html, such as with a binding to an `<input>` element's `value` property,
  19. * a content editable elements text, or to a custom element that changes it's
  20. * own properties or attributes.
  21. *
  22. * In these cases if the DOM value changes, but the value set through lit-html
  23. * bindings hasn't, lit-html won't know to update the DOM value and will leave
  24. * it alone. If this is not what you want--if you want to overwrite the DOM
  25. * value with the bound value no matter what--use the `live()` directive:
  26. *
  27. * ```js
  28. * html`<input .value=${live(x)}>`
  29. * ```
  30. *
  31. * `live()` performs a strict equality check agains the live DOM value, and if
  32. * the new value is equal to the live value, does nothing. This means that
  33. * `live()` should not be used when the binding will cause a type conversion. If
  34. * you use `live()` with an attribute binding, make sure that only strings are
  35. * passed in, or the binding will update every render.
  36. */
  37. export declare const live: (value: unknown) => import("../directive.js").DirectiveResult<typeof LiveDirective>;
  38. /**
  39. * The type of the class that powers this directive. Necessary for naming the
  40. * directive's return type.
  41. */
  42. export type { LiveDirective };
  43. //# sourceMappingURL=live.d.ts.map