HeinrichApfelmus / threepenny-gui

GUI framework that uses the web browser as a display.
https://heinrichapfelmus.github.io/threepenny-gui/
Other
441 stars 77 forks source link

DrumMachine question #199

Closed ethanabrooks closed 7 years ago

ethanabrooks commented 7 years ago

I have been playing around with DrumMachine.hs and I plan to adapt it to a project I am working on. I was hoping you could help me understand why, if line 53 -- sequence_ $ map (!! beat) kit -- is commented out, the 'beat: ' number doesn't update on the resulting webpage. It seems like the only thing that line should do is actually play the sound. It shouldn't affect the number being changed on the screen.

HeinrichApfelmus commented 7 years ago

This seemingly weird behavior is due to "call buffering". As of version 0.8, Threepenny will buffer JavaScript FFI calls and only send them to the browser when necessary. You can flush the buffer by hand (flushCallBuffer) or change to a different buffering mode. In this case, the beat function will flush the buffer (get UI.checked will do that).

In the next release, v0.8.1, I intend to improve the documentation and make onEvent flush the call buffer, so this confusion appears less often.

See also #163, #191, #192 .

ethanabrooks commented 7 years ago

Perfect! Adding flushCallBuffer after line 51 solved the problem. How does one change to a different buffering mode, as you suggested?

HeinrichApfelmus commented 7 years ago

setCallBufferMode

ethanabrooks commented 7 years ago

Ok. Makes sense. Thank you.