Skip to content

Commit b33e608

Browse files
committed
use Result.builder in README
1 parent 2a111ab commit b33e608

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Atom.runtime.addGlobalLayer(
171171
## Working with `Stream`s
172172

173173
```tsx
174-
import { Result, Atom, useAtom } from "@effect-atom/atom-react"
174+
import { Atom, Result, useAtom } from "@effect-atom/atom-react"
175175
import { Cause, Schedule, Stream } from "effect"
176176

177177
// This will be a simple Atom that emits a incrementing number every second.
@@ -203,21 +203,21 @@ const countPullAtom = Atom.pull(Stream.make(1, 2, 3, 4, 5))
203203
function CountPullAtomComponent() {
204204
const [result, pull] = useAtom(countPullAtom)
205205

206-
return Result.match(result, {
207-
onInitial: () => <div>Loading...</div>,
208-
onFailure: (error) => <div>Error: {Cause.pretty(error.cause)}</div>,
209-
onSuccess: (success) => (
206+
return Result.builder(result)
207+
.onInitial(() => <div>Loading...</div>)
208+
.onFailure((cause) => <div>Error: {Cause.pretty(cause)}</div>)
209+
.onSuccess(({ items }, { waiting }) => (
210210
<div>
211211
<ul>
212-
{success.value.items.map((item) => (
212+
{items.map((item) => (
213213
<li key={item}>{item}</li>
214214
))}
215215
</ul>
216216
<button onClick={() => pull()}>Load more</button>
217-
{success.waiting ? <p>Loading more...</p> : <p>Loaded chunk</p>}
217+
{waiting ? <p>Loading more...</p> : <p>Loaded chunk</p>}
218218
</div>
219-
),
220-
})
219+
))
220+
.render()
221221
}
222222
```
223223

tsconfig.base.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
"paths": {
3939
"@effect-atom/atom/test/*": ["./packages/atom/test/*.js"],
4040
"@effect-atom/atom/*": ["./packages/atom/src/*.js"],
41+
"@effect-atom/atom": ["./packages/atom/src/index.js"],
4142
"@effect-atom/atom-react/test/*": ["./packages/atom-react/test/*.js"],
4243
"@effect-atom/atom-react/*": ["./packages/atom-react/src/*.js"],
44+
"@effect-atom/atom-react": ["./packages/atom-react/src/index.js"],
4345
"@effect-atom/atom-vue/test/*": ["./packages/atom-vue/test/*.js"],
4446
"@effect-atom/atom-vue/*": ["./packages/atom-vue/src/*.js"]
4547
},

0 commit comments

Comments
 (0)