Todo optional ID
This commit is contained in:
@@ -9,7 +9,7 @@ export class Todo
|
||||
_kind: Kind("Todo"),
|
||||
_tag: Tag("Todo"),
|
||||
|
||||
id: S.String,
|
||||
id: S.OptionFromSelf(S.String),
|
||||
title: S.String,
|
||||
content: S.String,
|
||||
|
||||
@@ -26,6 +26,7 @@ export class Todo
|
||||
export const JsonifiableTodo = Todo.pipe(Jsonifiable(S.Struct({
|
||||
...Todo.fields,
|
||||
|
||||
id: S.OptionFromNullOr(S.String),
|
||||
due: S.OptionFromNullOr(S.DateFromString),
|
||||
createdAt: S.DateFromString,
|
||||
updatedAt: S.DateFromString,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Equal } from "effect"
|
||||
import { Equal, Option } from "effect"
|
||||
|
||||
|
||||
export interface Identifiable<
|
||||
@@ -6,7 +6,7 @@ export interface Identifiable<
|
||||
ID,
|
||||
> {
|
||||
readonly _kind: Kind
|
||||
readonly id: ID
|
||||
readonly id: Option.Option<ID>
|
||||
}
|
||||
|
||||
export module Identifiable {
|
||||
@@ -17,6 +17,9 @@ export module Identifiable {
|
||||
that: Identifiable<Kind, ID>,
|
||||
to: Identifiable<Kind, ID>,
|
||||
): boolean {
|
||||
return Equal.equals(that.id, to.id)
|
||||
// Two elements can only be equal if they both have a defined ID
|
||||
return Option.isSome(that.id) && Option.isSome(to.id)
|
||||
? Equal.equals(that.id, to.id)
|
||||
: false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user