reactive-controller.d.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * @license
  3. * Copyright 2021 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /**
  7. * An object that can host Reactive Controllers and call their lifecycle
  8. * callbacks.
  9. */
  10. export interface ReactiveControllerHost {
  11. /**
  12. * Adds a controller to the host, which sets up the controller's lifecycle
  13. * methods to be called with the host's lifecycle.
  14. */
  15. addController(controller: ReactiveController): void;
  16. /**
  17. * Removes a controller from the host.
  18. */
  19. removeController(controller: ReactiveController): void;
  20. /**
  21. * Requests a host update which is processed asynchronously. The update can
  22. * be waited on via the `updateComplete` property.
  23. */
  24. requestUpdate(): void;
  25. /**
  26. * Returns a Promise that resolves when the host has completed updating.
  27. * The Promise value is a boolean that is `true` if the element completed the
  28. * update without triggering another update. The Promise result is `false` if
  29. * a property was set inside `updated()`. If the Promise is rejected, an
  30. * exception was thrown during the update.
  31. *
  32. * @return A promise of a boolean that indicates if the update resolved
  33. * without triggering another update.
  34. */
  35. readonly updateComplete: Promise<boolean>;
  36. }
  37. /**
  38. * A Reactive Controller is an object that enables sub-component code
  39. * organization and reuse by aggregating the state, behavior, and lifecycle
  40. * hooks related to a single feature.
  41. *
  42. * Controllers are added to a host component, or other object that implements
  43. * the `ReactiveControllerHost` interface, via the `addController()` method.
  44. * They can hook their host components's lifecycle by implementing one or more
  45. * of the lifecycle callbacks, or initiate an update of the host component by
  46. * calling `requestUpdate()` on the host.
  47. */
  48. export interface ReactiveController {
  49. /**
  50. * Called when the host is connected to the component tree. For custom
  51. * element hosts, this corresponds to the `connectedCallback()` lifecycle,
  52. * which is only called when the component is connected to the document.
  53. */
  54. hostConnected?(): void;
  55. /**
  56. * Called when the host is disconnected from the component tree. For custom
  57. * element hosts, this corresponds to the `disconnectedCallback()` lifecycle,
  58. * which is called the host or an ancestor component is disconnected from the
  59. * document.
  60. */
  61. hostDisconnected?(): void;
  62. /**
  63. * Called during the client-side host update, just before the host calls
  64. * its own update.
  65. *
  66. * Code in `update()` can depend on the DOM as it is not called in
  67. * server-side rendering.
  68. */
  69. hostUpdate?(): void;
  70. /**
  71. * Called after a host update, just before the host calls firstUpdated and
  72. * updated. It is not called in server-side rendering.
  73. *
  74. */
  75. hostUpdated?(): void;
  76. }
  77. //# sourceMappingURL=reactive-controller.d.ts.map