ghcjs / ghcjs-base

base library for GHCJS for JavaScript interaction and marshalling, used by higher level libraries like JSC
MIT License
45 stars 67 forks source link

asyncCallback - performance and related questions #99

Open saurabhnanda opened 7 years ago

saurabhnanda commented 7 years ago

Context: How would callback heavy code perform under GHCJS? For example, most Elm-like architectures require a callback to triggered on almost every user-interaction to update the model state (eg. keypress in an input, on-hover to add/remove classes, etc.)

wereHamster commented 7 years ago

My approach is to export one callback at application startup, capture events at the root of the document (ie. add a single event listener to document.body), and dispatch the event manually to the correct place inside the Haskell code. That way JS/DOM doesn't have to retain any references to Haskell values, and I don't have to export/release tons of callbacks while the application is running.