A StorageKey
represents a value that is either New
or Existing
.
StorageKey
is a type that would be used normally as a key in an
EveryDict
or EveryDictList
to indicate if a value is already Existing
- that is, stored in the backend, or New
.
If used as a key for an EveryDict
we are guarnteed to have only a single New
.
A StorageKey
value is either New
or Existing
.
view : StorageKey -> Html msg
view storageKey =
case storageKey of
Existing recordId ->
text <| "Record ID is " ++ toString recordId
ReadOnly saved ->
text "Record was not saved yet"
isExisting : StorageKey recordId -> Basics.Bool
Determines if a StorageKey
is of type Existing
.
StorageKey.New
|> StorageKey.isExisting --> False
StorageKey.Existing "uuid-1234"
|> StorageKey.isExisting --> True
isNew : StorageKey recordId -> Basics.Bool
Determines if a StorageKey
is of type New
.
StorageKey.New
|> StorageKey.isNew --> True
StorageKey.Existing "uuid-1234"
|> StorageKey.isNew --> False
value : StorageKey recordId -> Maybe recordId
Gets the record ID value out of a StorageKey
if it is of type Existing
.
Otherwise, it retuens Nothing
.
StorageKey.New
|> StorageKey.value --> Nothing
StorageKey.Existing "uuid-1234"
|> StorageKey.value --> Just "uuid-1234"