ursi / purescript-elmish

this will have its own name eventually
https://github.com/ursi/purescript-package-set
3 stars 0 forks source link

init need not be a function #10

Open Quelklef opened 2 years ago

Quelklef commented 2 years ago

Currently,

init :: flags -> Update msg model

I assume this is inherited from Elm.

Because Purescript has main :: Effect a instead of main :: Program a b c like Elm, we actually don't need flags: instead of writing

main = do
  let app = Elmish.app { init: initialize, ... }
  myFlag <- getFlag
  runEffectFn1 myFlag app

We can write

main = do
  myFlag <- getFlag
  let app = Elmish.app { init: const (initialize myFlag) }
  runEffectFn1 unit app

As such, it seems appropriate to me to change init :: flags -> Update msg model to init :: Update msg model or even just init :: model.

Quelklef commented 2 years ago

If you think this would be an appropriate change, I can implement it; more opportunity to get comfy with the elmish codebase

Quelklef commented 2 years ago

Conclusion reached: make init :: Update msg model -- flags are unnecessary, but it's nice to do all those Effects within an initialization function

ursi commented 2 years ago

Also if you really need a flags-like api, you can wrap main and make it yourself