JordanMartinez / learn-halogen

Learn purescript-halogen using a bottom-up apporach via this "clone-and-play" repository
188 stars 28 forks source link

use forall instead of Void for empty queries, messages, inputs #80

Closed srghma closed 4 years ago

srghma commented 4 years ago

from https://github.com/JordanMartinez/learn-halogen/issues/65

it's also possible to use forall like

-- approach is used here 
-- https://github.com/purescript-halogen/purescript-halogen/blob/bb715fe5c06ba3048f4d8b377ec842cd8cf37833/examples/higher-order-components/src/Harness.purs#L43
-- https://github.com/purescript-halogen/purescript-halogen/blob/bb715fe5c06ba3048f4d8b377ec842cd8cf37833/examples/components-inputs/src/Container.purs#L39

simpleChildComponent :: forall query input messages . H.Component HH.HTML query () input messages Aff

-- and render using `unit` for values and `absurd` or `const unit` for functions

let index = unit -- or some integer
let input = unit -- or some datatype. On first render passed to `initialState` and to `receive` on subsequent renders if `input` is changed
let messageHandler = absurd -- or `Just <<< HandlePanelMessage`
HH.slot _proxy index simpleChildComponent input messageHandler

instead of

type MyQuery = Const Void
type MyInput = Void
type MyMessages = Void
simpleChildComponent :: H.Component HH.HTML MyQuery () MyInput MyMessages Aff
JordanMartinez commented 4 years ago

This tip should be added to the 'Various Tips and Tricks' file: https://github.com/JordanMartinez/learn-halogen/blob/latestRelease/src/08-Going-Deeper/06-Various-Tips-and-Tricks.md