Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Oct 26, 2024
1 parent 8035718 commit 9328903
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,53 @@ All the non-core functions are just examples of how you can compose functions to
npm install stalo
```

```tsx
import create from "stalo";
```js
import create, { peak, batch, dispose } from "stalo";

const a = create(0);
const b = create(1);
const c = create((use) => use(a) + use(b)); // tracked

create((use) => {
const [a, c] = use(a, c);
const b = peak(b); // untracked
console.log(a, c, d);
});

const list = create([]);
const itemAdded = create(0);

const filter = create(2);
const filtered = create([]);

function addItem(it) {
batch(list, itemAdded, (l) => {
l.push(it);
return [l, it];
});
}

const track = create((use) => {
const it = use(itemAdded);
if (it === peak(filter)) {
filtered((f) => {
f.push(it);
});
}
});

dispose(track);
```

const [useCount, setCount] = create(0);
```jsx
import { create, use } from "stalo";

const inc = () => setCount((c) => c + 1);
const count = create(0);

export default function App() {
return <button onClick={inc}>Count {useCount()}</button>;
return (
<button onClick={() => count((c) => c + 1)}>Count {use(count)}</button>
);
}
```

Expand Down

0 comments on commit 9328903

Please sign in to comment.