until.d.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @license
  3. * Copyright 2017 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. import { Part } from '../lit-html.js';
  7. import { AsyncDirective, DirectiveResult } from '../async-directive.js';
  8. type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
  9. export declare class UntilDirective<T> extends AsyncDirective {
  10. private __lastRenderedIndex;
  11. private __values;
  12. private __weakThis;
  13. private __pauser;
  14. render(...args: Array<T>): UnwrapPromise<T>;
  15. update(_part: Part, args: Array<unknown>): unknown;
  16. disconnected(): void;
  17. reconnected(): void;
  18. }
  19. interface Until {
  20. <T extends Array<unknown>>(...args: T): DirectiveResult<typeof UntilDirective<T[number]>>;
  21. }
  22. /**
  23. * Renders one of a series of values, including Promises, to a Part.
  24. *
  25. * Values are rendered in priority order, with the first argument having the
  26. * highest priority and the last argument having the lowest priority. If a
  27. * value is a Promise, low-priority values will be rendered until it resolves.
  28. *
  29. * The priority of values can be used to create placeholder content for async
  30. * data. For example, a Promise with pending content can be the first,
  31. * highest-priority, argument, and a non_promise loading indicator template can
  32. * be used as the second, lower-priority, argument. The loading indicator will
  33. * render immediately, and the primary content will render when the Promise
  34. * resolves.
  35. *
  36. * Example:
  37. *
  38. * ```js
  39. * const content = fetch('./content.txt').then(r => r.text());
  40. * html`${until(content, html`<span>Loading...</span>`)}`
  41. * ```
  42. */
  43. export declare const until: Until;
  44. export {};
  45. /**
  46. * The type of the class that powers this directive. Necessary for naming the
  47. * directive's return type.
  48. */
  49. //# sourceMappingURL=until.d.ts.map