live.d.ts 1.8 KB

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