paf31 / purescript-thermite

A simple PureScript wrapper for React
MIT License
350 stars 55 forks source link

Two state updates (cotransforms) in one performAction #65

Closed asvyazin closed 8 years ago

asvyazin commented 8 years ago

In some cases two cotransforms in one performAction don't work, second is just ignored

For example insert T.cotransform id into ChangeCompleted action handler in test/Components/Task.purs:

  performAction (ChangeCompleted b)   _ _ = do
    T.cotransform id
    void (T.cotransform (_ { completed = b }))

And btw two cotransforms work fine in TaskList handlers

asvyazin commented 8 years ago

There is another problem now... Now UI "waits" for final cotransform to re-render. Let's say you have something like:

performAction SomethingHappened _ _ = do
  T.cotransform $ \s -> s { showLoader = true }
  lift longAjaxRequest
  void $ T.cotransform $ \s -> s { showLoader = false }

then loader will not be shown at all. Should I start another issue?

paf31 commented 8 years ago

Thanks for pointing this out. This might be due to a problem in coroutines actually. We had a similar problem with producers and consumers at one point.

I'll have a look soon, but if you need a solution now, you might want to try switching around the order of the arguments to transformCoTransform.

paf31 commented 8 years ago

This is fixed by https://github.com/purescript-contrib/purescript-coroutines/pull/12

paf31 commented 8 years ago

This is fixed in master now.