watchTodoChanges work
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { BunRuntime } from "@effect/platform-bun"
|
||||
import { Todo } from "@todo-tests/common/data"
|
||||
import { Array, Effect, Fiber, Option, Stream } from "effect"
|
||||
import { Identifiable } from "@todo-tests/common/traits"
|
||||
import { Array, Duration, Effect, Fiber, Option, Stream } from "effect"
|
||||
import { TodoRepository, TodoRepositoryLive, createDefaultTodos } from "./TodoRepository"
|
||||
|
||||
|
||||
@@ -12,8 +13,8 @@ const watchTodoChanges = Effect.gen(function*() {
|
||||
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) }`)
|
||||
console.log(`Added todos: ${ Array.differenceWith<Todo>(Identifiable.equals)(curr, prev) }`)
|
||||
console.log(`Removed todos: ${ Array.differenceWith<Todo>(Identifiable.equals)(prev, curr) }`)
|
||||
|
||||
return curr
|
||||
},
|
||||
@@ -27,18 +28,27 @@ const main = Effect.gen(function*() {
|
||||
yield* createDefaultTodos
|
||||
|
||||
const todos = yield* TodoRepository
|
||||
// console.log(yield* todos.todos.get)
|
||||
|
||||
const secondTodo = yield* yield* todos.todos.get.pipe(
|
||||
Effect.map(Array.get(1))
|
||||
// const secondTodo = yield* yield* todos.todos.get.pipe(
|
||||
// Effect.map(Array.get(1))
|
||||
// )
|
||||
// const secondTodoModified = new Todo({
|
||||
// ...secondTodo,
|
||||
// completed: true,
|
||||
// })
|
||||
// yield* todos.update(secondTodoModified)
|
||||
|
||||
yield* todos.add(new Todo({
|
||||
id: Option.none(),
|
||||
title: "Put the dishes in the dishwasher",
|
||||
content: "Lorem ipsum",
|
||||
due: Option.none(),
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})).pipe(
|
||||
Effect.delay(Duration.seconds(1))
|
||||
)
|
||||
const secondTodoModified = new Todo({
|
||||
...secondTodo,
|
||||
completed: true,
|
||||
})
|
||||
|
||||
yield* todos.update(secondTodoModified)
|
||||
// console.log(yield* todos.todos.get)
|
||||
|
||||
yield* Fiber.join(watcher)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user