-
Notifications
You must be signed in to change notification settings - Fork 17
Concur Vs. Elm
Concur is strictly more powerful, while also being easier to use than The Elm Architecture.
-
With Concur, there's no magic with effects and actions involved. A 'Widget' means a very simple thing - A section of UI which returns a value. Using this single concept, it's trivial to recreate the Elm architecture, but while remaining in full control, and understanding every step of the process.
-
There is no global state, and you can use local state with as fine a granularity as desired. Moreover, the resulting widget can be used within other widgets without having to thread in its state manually. EVerything just works!
Here's an example of building a small form with Concur -
-- Like Elm State
type Form =
{ name :: String
, rememberMe :: Bool
}
-- Like Elm Action
data FormAction
= Name String
| RememberMe Bool
| Submit
formWidget form = do
-- This is like Elm's view
res <- div'
[ Name <$> textInput form.name
, RememberMe <$> checkboxInput form.rememberMe
, Submit <$ button "Submit"
]
-- This is like Elm's update
case res of
Name s -> formWidget (form {name = s})
RememberMe b -> formWidget (form {rememberMe = b})
Submit -> pure form
Now you can use formWidget
as a regular widget anywhere else in the rest of your application. Note that the other parts of your application don't need to know about FormAction
at all.