Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when using a function as the type of a message #78

Open
SATBH opened this issue Jul 8, 2023 · 2 comments
Open

Bug when using a function as the type of a message #78

SATBH opened this issue Jul 8, 2023 · 2 comments

Comments

@SATBH
Copy link

SATBH commented Jul 8, 2023

The minimal reproducible example would be this.

module Main where

import Prelude

import Effect (Effect)
import Flame.Application.NoEffects (mount_)
import Flame.Html.Element as HE
import Flame.Types (Html, Subscription)
import Flame.Html.Attribute as HA
import Flame (QuerySelector(..))

type Model = Int
type Message = Model -> Model

init :: Model
init = 0

subscribe :: Array (Subscription Message)
subscribe = []

view :: Model -> Html Message
view model = HE.button [HA.onClick ((+) 1)] (show model)

update :: Model -> Message -> Model
update model message = message model

main :: Effect Unit
main = do
  mount_ (QuerySelector "body") { init, subscribe, view, update}

I get that the point of messages is to limit the type of mutations one can do on the model. But I was playing around with that, since it allows me to try some things faster while i decide how to structure the state and its mutations. Trying this however fails, and when the button is clicked the following error is logged

caught TypeError: h(...) is not a function
    at F.runHandlers (index.js:2273:51)
    at F.runEvent (index.js:2264:14)

Is this known?

@easafe
Copy link
Owner

easafe commented Jul 11, 2023

Hello @SATBH ,

Thanks for bringing this up. I don't think anyone have tried to use a function as message type. It should be possible to patch but were you thinking of using function just to avoid defining sum types?

@SATBH
Copy link
Author

SATBH commented Jul 11, 2023

I mean, I do think using a Sum type is the better choice. I just was playing around mostly, since i'm currently learning purescript and flame. And wanted to edit the model loosely cause i didn't want to plan ahead for the most part and discovered the bug. If it helps, wrapping the function in another type solves it. And sending a message with send doesn't trigger it either. I am just opening the issue for robustness' sake mostly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants