watchTodoChanges tests
This commit is contained in:
@@ -1,12 +1,24 @@
|
||||
import { BunRuntime } from "@effect/platform-bun"
|
||||
import { Todo } from "@todo-tests/common/data"
|
||||
import { Array, Console, Effect, Fiber, Stream } from "effect"
|
||||
import { Array, Effect, Fiber, Option, Stream } from "effect"
|
||||
import { TodoRepository, TodoRepositoryLive, createDefaultTodos } from "./TodoRepository"
|
||||
|
||||
|
||||
const watchTodoChanges = Effect.gen(function*() {
|
||||
const todos = yield* TodoRepository
|
||||
yield* Stream.runForEach(todos.todos.changes, todos => Console.log(`Todos changed: ${ todos }`))
|
||||
// yield* Stream.runForEach(todos.todos.changes, todos => Console.log(`Todos changed: ${ todos }`))
|
||||
yield* todos.todos.changes.pipe(
|
||||
Stream.runFold(
|
||||
Array.empty<Todo & { id: Option.Some<string> }>(),
|
||||
|
||||
(prev, curr) => {
|
||||
console.log(`Added todos: ${ Array.difference(curr, prev) }`)
|
||||
console.log(`Removed todos: ${ Array.difference(prev, curr) }`)
|
||||
|
||||
return curr
|
||||
},
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user