Skip to content

Commit

Permalink
Updates README with new component API and cleans up some comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgp1130 committed Dec 4, 2024
1 parent 9d9219f commit 54aa762
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@ It does this by providing an API to define custom elements with useful lifecycle
convenient DOM APIs. One example would be:

```typescript
import { ElementAccessor, defineComponent } from 'hydroactive';
import { ElementAccessor, component } from 'hydroactive';
import { WriteableSignal } from 'hydroactive/signals.js';

// `defineComponent()` creates a web component class based on the given hydrate
// function. The callback is invoked on hydration and provides `host` and `comp`
// parameters with additional functionality to provide interactivity to the
// pre-rendered component. Automatically calls `customElements.define` under the
// hood.
const MyCounter = defineComponent('my-counter', (host) => {
// `component()` creates a web component class based on the given hydration
// function. The callback is invoked on hydration and provides `host` parameter
// with additional functionality to provide interactivity to the pre-rendered
// component.
const MyCounter = component('my-counter', (host) => {
// Interacting with a site using HydroActive is a three-step process:
// 1. Query it - `host.query` queries the DOM for the selector and asserts
// it is found.
Expand Down Expand Up @@ -108,6 +107,9 @@ const MyCounter = defineComponent('my-counter', (host) => {
});
});

// Define the custom element, upgrading any `<my-element>` tags on the page.
MyCounter.define();

// For TypeScript, don't forget to type `my-counter` tags as an instance of the
// class.
declare global {
Expand Down

0 comments on commit 54aa762

Please sign in to comment.