Last active
May 12, 2019 03:24
-
-
Save JordanMartinez/9f27fb45f36fc2c0423185be2faba22c to your computer and use it in GitHub Desktop.
Finalizers not being run?
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
<!DOCTYPE html> | |
<html lang="en" dir="ltr"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Lifecycle - Child</title> | |
</head> | |
<body> | |
<script src="/main.js" charset="utf-8"></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
module Main where | |
import Prelude | |
import Data.Const (Const) | |
import Data.Maybe (Maybe(..)) | |
import Effect (Effect) | |
import Effect.Aff (Aff, Milliseconds(..), delay, launchAff_) | |
import Effect.Console (log) | |
import Halogen (liftEffect) | |
import Halogen as H | |
import Halogen.Aff (awaitBody) | |
import Halogen.HTML as HH | |
import Halogen.HTML.Events as HE | |
import Halogen.VDom.Driver (runUI) | |
main :: Effect Unit | |
main = do | |
launchAff_ do | |
body <- awaitBody | |
io <- runUI childLifecycleComponent unit body | |
delay $ Milliseconds 3000.0 | |
io.dispose | |
type State = Unit | |
type Input = Unit | |
type Message = Unit | |
data Action | |
= ButtonClicked | |
| Initialize | |
| Finalize | |
type Query = Const Void | |
type NoChildSlots = () | |
type MonadType = Aff | |
childLifecycleComponent :: H.Component HH.HTML Query Input Message MonadType | |
childLifecycleComponent = | |
H.mkComponent | |
{ initialState: identity | |
, render | |
, eval: H.mkEval $ H.defaultEval { handleAction = handleAction | |
, initialize = Just Initialize | |
, finalize = Just Finalize | |
} | |
} | |
where | |
render :: State -> H.ComponentHTML Action NoChildSlots Aff | |
render _ = | |
HH.button | |
[ HE.onClick \_ -> Just ButtonClicked ] | |
[ HH.text $ "Click me." | |
] | |
handleAction :: Action | |
-> H.HalogenM State Action NoChildSlots Message Aff Unit | |
handleAction = case _ of | |
Initialize -> do | |
liftEffect $ log "Component was initialized" | |
ButtonClicked -> do | |
liftEffect $ log "Button was clicked!" | |
Finalize -> do | |
liftEffect $ log "Component was removed" |
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
let mkPackage = | |
https://raw.githubusercontent.com/purescript/package-sets/psc-0.12.5-20190427/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57 | |
let upstream = | |
https://raw.githubusercontent.com/purescript/package-sets/psc-0.12.5-20190427/src/packages.dhall sha256:6b17811247e1f825034fa4dacc4b8ec5eddd0e832e0e1579c2ba3b9b2a1c63fe | |
let overrides = | |
{ halogen = | |
upstream.halogen // { version = "v5.0.0-rc.4" } | |
, halogen-vdom = | |
upstream.halogen-vdom // { version = "v6.1.0" } | |
} | |
let additions = {=} | |
in upstream // overrides // additions |
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
{ name = | |
"my-project" | |
, dependencies = | |
[ "console" | |
, "css" | |
, "effect" | |
, "halogen" | |
, "halogen-css" | |
, "psci-support" | |
, "random" | |
] | |
, packages = | |
./packages.dhall | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment