0
votes

I am working on integrating the event system with om-event-bus, it use async/chan to transfer the events. However, it turns out html DOM event failed to be transfer through clojurescript's async channel. The properties in the transferred event becomes null and the internal functions are missing.

Define a channel first:

(def event-bus (chan))

Setup a dom node and attach a callback function to the keydown event. In the function, add the put the dom event in the channel (PS:I use om as UI)

(dom/section #js {:id "VRE" 
                  :tabIndex 0
                  :onKeyDown  #(put! event-bus %)))

wait to receive the event transferred

(go-loop
  []
  (let [e (<! event-bus)]
    (when e
      (println "go-loop received" (.stringify js/JSON e))
      (recur))))

When I type some key, the console will print:

go-loop received {"dispatchConfig":null,
                  "dispatchMarker":null,
                  "nativeEvent":null,
                  "type":null,
                  ...
                  "_dispatchListeners":null,"_dispatchIDs":null}

All the properties are null and the internal functions like preventDefault are missing.

I guess there must be something I haven't understood. Does anyone have some ideas for fixing it? It would be great if you could give some hints/tips or other thoughts on the problem

1

1 Answers

0
votes

You are trying to stringify an Event Object. This is not a good idea, look at this answer:

How to stringify event object?

Try extracting the interesting information (i.e which key was pressed) and passing that as a value to the channel.

To pass the whole Event Object and manipulating it on the receiving end might not be possible. I'm speculating but it seems like the Event Object is deleted before it is extracted from the channel.