mikesol / purescript-deku

A PureScript web UI framework
https://purescript-deku.surge.sh/
Apache License 2.0
123 stars 12 forks source link

Provider state is not consistent #114

Closed jerbaroo closed 5 months ago

jerbaroo commented 5 months ago

Love your library, but would really appreciate some feedback on this issue. Been wrecking my head for hours.

Description of issue (images below):

  1. I have an Env with some state shown as "Foo" in the top bar, and again in a component below it.
  2. Then I click the "TEST" button, which changes the state to "Bar".
  3. Then I click to the next tab, and back to the first tab. Now the top bar still shows "Bar" (as it should), but the bottom component has gone back to the initial state "Foo"! How can the state be inconsistent !

I believe this should be enough of the code for you to probably easily pinpoint what I am doing wrong. Thank you!

app :: Nut
app = runAppM app'

app' :: AppM
app' = do
  { mapLocation, route, setRoute } <- ask
  myMap' <- myMap
  pure $ D.div [DA.id_ "app"]
    [ D.div [DA.id_ "app-body"]
      [ text $ mapLocation <#> \l -> l.name
      , route <#~> Navbar.navbar setRoute
      , route <#~> case _ of
          Navbar.Map -> myMap'
          _ -> D.div_ [text_ "TODO"]
      ]
    ]

myMap :: AppM
myMap = do
  { setMapLocation, mapLocation } <- ask
  pure $ D.div_
    [ mapLocation <#~> \l -> text_ l.name
    , D.button
        [ DL.click_ \_ -> setMapLocation Location.bar ]
        [ text_ "TEST" ]
    ]

1. image

2 image

3. image

jerbaroo commented 5 months ago

The solution was to switch to useHot