paf31 / purescript-sdom

An experiment in replacing the virtual DOM and avoiding diffing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support async event handlers?

chexxor opened this issue · comments

I don't use this lib yet, so no time constraint on responding to this issue. I've been looking at it a lot and am finding it great reference.

If I'm reading the code right, the eventListeners/handlers currently are synchronous. I wonder if Phil has already considered the async handler situation in this lib and precluded async handlers.

(Event -> i -> o)

It's inevitable that this lib will need to support async handlers. Maybe change the type of a handler to something like this:

type EventHandler m i o = (Event -> i -> ContT Unit m o)
-- Could prescribe `Run`. Surely no complaints - everyone likes trying a new thing. :-)
type EventHandlerRun effs i o = EventHandler (Run effs)

It would require updating runStaticDOM and I think it would be used like this:

element "button"
        (mempty)
        (singleton "click" \_ xs -> pure $ (length xs) : xs)
        -- or --
        (singleton "click" \_ xs -> do
          x <- fetchXInContT
          pure x : xs
        [ text $ const "+ Add" ]

Right now, this is just an experiment and I'd like to not complicate it with asynchronous code. People can take the idea and use it to build something for real-world use, but I have more ideas to try here before polishing it up and publishing it.

I've put up an example here.