Created
November 9, 2020 13:57
-
-
Save mpscholten/7558084941f3ebf6c1e6950e2db713c6 to your computer and use it in GitHub Desktop.
serversidecomponentwithactions.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | |
|] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can't wait to this! :)