Closed mikavilpas closed 9 years ago
Mark more than likely you are adding new handlers to the channel events on save.
Or you are passing the dispatch handler by value to sente. Or a number of things, but I can't tell anything from the code you have given me.
On Fri, Mar 27, 2015 at 9:18 AM, Mika Vilpas notifications@github.com wrote:
I'd like to try setting up sente event handlers with multimethods. Are they supported? I can see some changes if I (def my-multi-method nil) before re-declaring the multimethod, but it seems both the old multimethod and the new one being reloaded run.
Reloading my app's web page manually ends up only using the new implementation, as expected.
Here's a snippet with something I'm trying out:
(def chat-event-dispatcher nil) (defmulti chat-event-dispatcher first) (defmethod chat-event-dispatcher :default [event](print "unknown server event" %28:id event)))
(defmethod chat-event-dispatcher :server/send-new-messages [_event-id {:keys [data]}] event (swap! update-in app-state [:messages] #(concat % data)))
If I change "old implementation" to "new implementation" both multimethods are ran with the file being saved.
— Reply to this email directly or view it on GitHub https://github.com/bhauman/lein-figwheel/issues/117.
Ah those are good suggestions. I'll review my code. I take it multimethods are supported then? 27.3.2015 16.15 kirjoitti "Bruce Hauman" notifications@github.com:
Mark more than likely you are adding new handlers to the channel events on save.
Or you are passing the dispatch handler by value to sente. Or a number of things, but I can't tell anything from the code you have given me.
On Fri, Mar 27, 2015 at 9:18 AM, Mika Vilpas notifications@github.com wrote:
I'd like to try setting up sente event handlers with multimethods. Are they supported? I can see some changes if I (def my-multi-method nil) before re-declaring the multimethod, but it seems both the old multimethod and the new one being reloaded run.
Reloading my app's web page manually ends up only using the new implementation, as expected.
Here's a snippet with something I'm trying out:
(def chat-event-dispatcher nil) (defmulti chat-event-dispatcher first) (defmethod chat-event-dispatcher :default [event](print "unknown server event" %28:id event)))
(defmethod chat-event-dispatcher :server/send-new-messages [_event-id {:keys [data]}] event (swap! update-in app-state [:messages] #(concat % data)))
If I change "old implementation" to "new implementation" both multimethods are ran with the file being saved.
— Reply to this email directly or view it on GitHub https://github.com/bhauman/lein-figwheel/issues/117.
— Reply to this email directly or view it on GitHub https://github.com/bhauman/lein-figwheel/issues/117#issuecomment-86952976 .
defmulti
has the same semantics as defonce
- see CLJ-900. I think you can just extract the implementation out into a separate function to make it reloadable.
figwheel does nothing special for multimethods. You have to be aware of their loading semantics. They actually don't have defonce
behavior right now. http://dev.clojure.org/jira/browse/CLJS-1175
Yep, looks like you guys were right. My problem was I had a sente-setup function to which I passed my chat-event-dispatcher. I removed the argument and hard coded the dependency to this specific function. Now it looks like I can just change the multimethod in place and figwheel reloads the new code immediately, like I expected it to. Awesome! :)
I'd like to try setting up sente event handlers with multimethods. Are they supported? I can see some changes if I
(def my-multi-method nil)
before re-declaring the multimethod, but it seems both the old multimethod and the new one being reloaded run.Reloading my app's web page manually ends up only using the new implementation, as expected.
Here's a snippet with something I'm trying out:
If I change "old implementation" to "new implementation" both multimethods are ran with the file being saved.