taoensso / sente

Realtime web comms library for Clojure/Script
https://www.taoensso.com/sente
Eclipse Public License 1.0
1.74k stars 193 forks source link

Incomplete event-msg reference: ev-id and ?ev-data are the same as id and ?data ? #305

Closed vspinu closed 6 years ago

vspinu commented 7 years ago

Would it be possible to elaborate a bit more on all of the components of the event-msg in the readme's table?

Do I understand correctly that ?data and id within event-msg are always the same as the first and second elements of event? Why is this seemingly useless repetition?

theasp commented 6 years ago

I believe you are asking about the result of this, for the server, or the similar logic on the client side:

(defn- put-server-event-msg>ch-recv!
  "All server `event-msg`s go through this"
  [ch-recv {:as ev-msg :keys [event ?reply-fn]}]
  (let [[ev-id ev-?data :as valid-event] (as-event event)
        ev-msg* (merge ev-msg {:event     valid-event
                               :?reply-fn ?reply-fn
                               :id        ev-id
                               :?data     ev-?data})]
    (if-not (server-event-msg? ev-msg*)
      (warnf "Bad ev-msg: %s" ev-msg) ; Log 'n drop
      (put! ch-recv ev-msg*))))

I think, and I could be wrong, but the data inside the event won't be duplicated here. ev-msg is an object that references id and ?data, and event. event also references the same data structures in id and ?data.

ptaoussanis commented 6 years ago

Hi Vitalie,

Do I understand correctly that ?data and id within event-msg are always the same as the first and second elements of event? Why is this seemingly useless repetition?

That's correct - they are the same. The repetition is for historical (backward-compatibility) reasons.

Hope that helps?

vspinu commented 6 years ago

Yes. Thanks for the clarification.