Skip to content

Concur Vs. Elm

Anupam Jain edited this page Jun 11, 2018 · 1 revision

Concur is strictly more powerful, while also being easier to use than The Elm Architecture.

  1. 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.

  2. 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.

Clone this wiki locally