Skip to content

Instantly share code, notes, and snippets.

@mpscholten
Created November 9, 2020 13:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpscholten/7558084941f3ebf6c1e6950e2db713c6 to your computer and use it in GitHub Desktop.
Save mpscholten/7558084941f3ebf6c1e6950e2db713c6 to your computer and use it in GitHub Desktop.
serversidecomponentwithactions.hs
data Counter = Counter { value :: Int }
data CounterController = IncrementCounterAction
instance Component CounterController Counter where
initialState = Counter { value = 0 }
-- Should alos support lifecycle hooks
componentWillMount = ...
componentDidMount = ..
componentWillUnmount = ...
render Counter { value } = [hsx|Current: {value} <button onClick={dispatchAction IncrementCounterAction}>Plus One</button>|]
action IncrementCounterAction = do
setState (\Counter { value } -> Counter { value = value + 1 })
-- How to mount this:
[hsx|
<h1>Counter</h1>
{component @Counter}
|]
@andreatrygit
Copy link

Can't wait to this! :)

@s0kil
Copy link

s0kil commented Dec 2, 2020

Looks like Elm server-side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment