From 93289036269b03bd057747c1b0348a2dbde55cc3 Mon Sep 17 00:00:00 2001 From: Yad Smood <1415488+ysmood@users.noreply.github.com> Date: Sat, 26 Oct 2024 11:54:41 +0800 Subject: [PATCH] up --- README.md | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4e84390..56e03fc 100644 --- a/README.md +++ b/README.md @@ -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 ; + return ( + + ); } ```