-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8149f55
commit ed6e0ae
Showing
7 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/bower_components/ | ||
/node_modules/ | ||
/.pulp-cache/ | ||
/output/ | ||
/generated-docs/ | ||
/.psc-package/ | ||
/.psc* | ||
/.purs* | ||
/.psa* | ||
/.spago | ||
/web-dist/ | ||
/prod-dist/ | ||
/prod/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ComponentsInputHalogenHooks | ||
|
||
Each time a parent re-renders, it will pass a new input value into the child, and the child will update accordingly. | ||
|
||
## Expected Behavior: | ||
|
||
### Browser | ||
|
||
The parent stores an `Int`. Clicking the buttons will increment/decrement that value. The children will produce the result of a mathematical computation using that value. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ name = "ComponentsInputHalogenHooks" | ||
, dependencies = | ||
[ "console" | ||
, "effect" | ||
, "halogen-hooks" | ||
, "halogen-hooks-extra" | ||
, "psci-support" | ||
] | ||
, packages = ../../packages.dhall | ||
, sources = [ "recipes/ComponentsInputHalogenHooks/src/**/*.purs" ] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module ComponentsInputHalogenHooks.Main where | ||
|
||
import Prelude hiding (top) | ||
|
||
import Data.Maybe (Maybe(..), maybe) | ||
import Data.Symbol (SProxy(..)) | ||
import Data.Tuple.Nested ((/\)) | ||
import Effect (Effect) | ||
import Effect.Class (class MonadEffect) | ||
import Halogen as H | ||
import Halogen.Aff as HA | ||
import Halogen.HTML as HH | ||
import Halogen.HTML.Events as HE | ||
import Halogen.HTML.Properties as HP | ||
import Halogen.Hooks as Hooks | ||
import Halogen.Hooks.Extra.Hooks.UseGet (useGet) | ||
import Halogen.VDom.Driver (runUI) | ||
|
||
main :: Effect Unit | ||
main = | ||
HA.runHalogenAff do | ||
body <- HA.awaitBody | ||
void $ runUI containerComponent unit body | ||
|
||
_button :: SProxy "button" | ||
_button = SProxy | ||
|
||
containerComponent | ||
:: forall unusedQuery unusedInput unusedOutput anyMonad | ||
. MonadEffect anyMonad | ||
=> H.Component HH.HTML unusedQuery unusedInput unusedOutput anyMonad | ||
containerComponent = Hooks.component \_ _ -> Hooks.do | ||
state /\ stateIdx <- Hooks.useState 0 | ||
Hooks.pure $ | ||
HH.div_ | ||
[ HH.ul_ | ||
[ HH.slot _display 1 displayComponent state absurd | ||
, HH.slot _display 2 displayComponent (state * 2) absurd | ||
, HH.slot _display 3 displayComponent (state * 3) absurd | ||
, HH.slot _display 4 displayComponent (state * 10) absurd | ||
, HH.slot _display 5 displayComponent (state * state) absurd | ||
] | ||
, HH.button | ||
[ HE.onClick \_ -> Just $ Hooks.modify_ stateIdx (_ + 1) ] | ||
[ HH.text "+1"] | ||
, HH.button | ||
[ HE.onClick \_ -> Just $ Hooks.modify_ stateIdx (_ - 1) ] | ||
[ HH.text "-1"] | ||
] | ||
|
||
_display = SProxy :: SProxy "display" | ||
|
||
displayComponent | ||
:: forall unusedQuery unusedOutput anyMonad | ||
. MonadEffect anyMonad | ||
=> H.Component HH.HTML unusedQuery Int unusedOutput anyMonad | ||
displayComponent = Hooks.component \_ input -> Hooks.do | ||
latestInput <- useGet input | ||
Hooks.pure $ | ||
HH.div_ | ||
[ HH.text "My input value is:" | ||
, HH.strong_ [ HH.text (show latestInput) ] | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>ComponentsInputHalogenHooks</title> | ||
</head> | ||
|
||
<body> | ||
<script src="./index.js"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"use strict"; | ||
require("../../../output/ComponentsInputHalogenHooks.Main/index.js").main(); |