TodoRepository work
This commit is contained in:
@@ -1,9 +1,33 @@
|
||||
import { Todo } from "@todo-tests/common/data"
|
||||
import { Array, Context, Effect, Option, Ref } from "effect"
|
||||
import { Array, Context, Effect, Option, Ref, SubscriptionRef } from "effect"
|
||||
|
||||
|
||||
export class TodoRepository extends Context.Tag("TodoRepository")<TodoRepository, Ref.Ref<Todo[]>>() {}
|
||||
|
||||
export class TodoRepositoryService {
|
||||
constructor(
|
||||
readonly ref: SubscriptionRef.SubscriptionRef<Todo[]>
|
||||
) {}
|
||||
|
||||
get(id: string) {
|
||||
return this.ref.get.pipe(
|
||||
Effect.map(Array.findFirst(todo => todo.id === id))
|
||||
)
|
||||
}
|
||||
getIndex(id: string) {
|
||||
return this.ref.get.pipe(
|
||||
Effect.map(Array.findFirstIndex(todo => todo.id === id))
|
||||
)
|
||||
}
|
||||
|
||||
update(todo: Todo) {
|
||||
return Effect.gen(this, function*() {
|
||||
const todoWithSameIDIndex = yield* this.getIndex(todo.id)
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const createDefaultTodos = TodoRepository.pipe(Effect.flatMap(repo =>
|
||||
Ref.update(repo, todos =>
|
||||
|
||||
Reference in New Issue
Block a user