Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
loreanvictor committed Jul 16, 2023
1 parent f0fe981 commit 1b80d55
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,33 @@ define('say-hi', ({ to }) => `<div>Hellow ${to}</div>`)
👉 Use hooks to tap into [custom elements' life cycle callbacks](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#using_the_lifecycle_callbacks):

```js
import { define, onAttribute } from 'minicomp'
import { define, onConnected, onDisconnected } from 'minicomp'

define('say-hi', () => {
define('my-el', () => {
onConnected(() => console.log('CONNECTED!'))
onDisconnected(() => console.log('DISCONNECTED'))

return '<div>Hellow World!</div>'
})
```
Or to respond to changes:
```js
import { define, onAttribute, currentNode } from 'minicomp'

define('say-hi', () => {
const host = currentNode().shadowRoot
onAttribute('to', name => {
host.querySelector('span').textContent = name
})

return '<div>Hellow <span></span></div>'
})
```
<div align="right">

[**▷ TRY IT**](https://codepen.io/lorean_victor/pen/NWEYggY)

</div>

<br><br>

Expand Down Expand Up @@ -156,6 +174,23 @@ onAttribute(
```
Is called with the initial value of specified attribute (`undefined` if not passed initially) and whenever the value of specified attribute changes (via `.setAttribute()`). Will be called with `ATTRIBUTE_REMOVED` symbol when specified attribute is removed (via `.removeAttribute()`).

```js
import { define, onAttribute } from 'minicomp'
import { ref, html } from 'rehtm'

define('say-hi', () => {
const span = ref()
onAttribute('to', name => span.current.textContent = name)

return html`<div>Hellow <span ref=${span}></span></div>`
})
```
<div align="right">

[**▷ TRY IT**](https://codepen.io/lorean_victor/pen/dyQmRzM)

</div>

<br>

### onProperty
Expand Down

0 comments on commit 1b80d55

Please sign in to comment.