Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified deconstructors #11

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions example/src/Sink.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Ur.Constructor as C
import Ur.Deconstructor as D
import Ur.Run
import Ur.Sub
import Ur.Types exposing (Noun)
import Widget
import Widget.Icon as Icon
import Widget.Material as Material
Expand Down Expand Up @@ -56,7 +55,7 @@ main =
, app = "journal"
, path = [ "sync" ]
, deconstructor =
D.list (D.cell D.bigint D.cord |> D.map (\a b -> ( a, b )))
D.list (D.cell D.bigint D.cord)
|> D.map GotListings
}
]
Expand Down
19 changes: 10 additions & 9 deletions example/src/Vanilla.elm
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ main =
, success =
D.cell D.ignore
(D.cell (D.const D.cord "jrnl")
(D.list (D.cell D.bigint D.cord |> D.map (\a b -> ( a, b ))))
|> D.map GotListings
(D.list (D.cell D.bigint D.cord))
)
|> D.map (\( (), ( (), listings ) ) -> GotListings listings)
}
]
|> Ur.Cmd.cmd
Expand Down Expand Up @@ -177,14 +177,15 @@ type JournalUpdate
| Delete BigInt


decodeJournalUpdate : D.Deconstructor (JournalUpdate -> a) a
decodeJournalUpdate : D.Deconstructor JournalUpdate
decodeJournalUpdate =
D.cell D.ignore <|
D.oneOf
[ (D.cell (D.const D.cord "add") <| D.cell D.bigint D.cord) |> D.map Add
, (D.cell (D.const D.cord "edit") <| D.cell D.bigint D.cord) |> D.map Edit
, D.cell (D.const D.cord "del") D.bigint |> D.map Delete
]
D.oneOf
[ (D.cell (D.const D.cord "add") <| D.cell D.bigint D.cord) |> D.map (\( (), ( id, txt ) ) -> Add id txt)
, D.cell (D.const D.cord "edit") (D.cell D.bigint D.cord) |> D.map (\( (), ( id, txt ) ) -> Edit id txt)
, D.cell (D.const D.cord "del") D.bigint |> D.map (\( (), id ) -> Delete id)
]
|> D.cell D.ignore
|> D.map (\( (), upd ) -> upd)


view : Model -> Document Msg
Expand Down
4 changes: 2 additions & 2 deletions src/Ur.elm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ scry :
, agent : Agent
, path : Path
, error : msg
, success : D.Deconstructor (msg -> msg) msg
, success : D.Deconstructor msg
}
-> Cmd msg
scry args =
Expand All @@ -91,7 +91,7 @@ scryTask :
, agent : Agent
, path : Path
, error : msg
, success : D.Deconstructor (msg -> msg) msg
, success : D.Deconstructor msg
}
-> Task a msg
scryTask { url, agent, path, error, success } =
Expand Down
Loading