Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
heyMP authored Jul 2, 2024
1 parent d06eef1 commit 98bccbd
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ for await (const value of count) {
}
```


## Lit

The cool thing about using AsyncIterators is that frameworks can expose
methods for re-rendering components when new values are yielded.

Expand All @@ -75,6 +72,56 @@ export class MyElement extends LitElement {
}
```

## Adapters

This library exposes framework specific adapters to make it easy to
sync changes of the Signals to trigger the component render lifecycle.

### React

```tsx
import { Signal } from '@heymp/signals';
import { useSignal } from '@heymp/signals/react';

const counter = new Signal.State(0);

function App() {
const [count] = useSignal(counter);

return (
<>
<button onClick={() => counter.value++}>
count is {count}
</button>
</>
);
}
```

### Lit

```ts
import { LitElement, html } from 'lit'
import { State } from '@heymp/signals';
import { watchSignal } from '@heymp/signals/lit';

export class MyCounter extends LitElement {
@watchSignal
private count?: State<number>;

@watchSignal
private message = new State('hello, world');

render() {
return html`
${this.message.value} ${this.count?.value}
`
}
}

}
```

## Signals Standard

There has been some awesome work done by Rob Eisenberg and library authors
Expand Down

0 comments on commit 98bccbd

Please sign in to comment.