Allow registration and de-registration of post event callbacks via an id.
This commit is contained in:
parent
05c1e1fbd9
commit
e2034f4576
|
@ -113,7 +113,8 @@ Joking aside, this is a substantial release which will change how you use re-fra
|
|||
##### Improvements
|
||||
|
||||
- Bug fix: `post-event-callbacks` were not called when `dispatch-sync` was called.
|
||||
- added new API `re-frame.core/remove-post-event-callback`. See doc string.
|
||||
- added new API `re-frame.core/clear-post-event-callback` which de-registers a callback
|
||||
added by `re-frame.core/add-post-event-callback`
|
||||
- when an event-handler makes no change to `app-db`, the `debug` middleware now logs a
|
||||
single line saying so, rather than a "group". Makes it slightly easier to grok
|
||||
the absence of change.
|
||||
|
|
|
@ -87,18 +87,22 @@
|
|||
- you want to create your own handling infrastructure, with perhaps multiple
|
||||
handlers for the one event, etc. Hook in here.
|
||||
- libraries providing 'isomorphic javascript' rendering on Nodejs or Nashorn.
|
||||
|
||||
'id' is typically a keyword.
|
||||
"
|
||||
[f]
|
||||
(router/add-post-event-callback re-frame.router/event-queue f))
|
||||
([f]
|
||||
(router/add-post-event-callback re-frame.router/event-queue f f))
|
||||
([id f]
|
||||
(router/add-post-event-callback re-frame.router/event-queue id f)))
|
||||
|
||||
|
||||
(defn remove-post-event-callback
|
||||
[f]
|
||||
(router/remove-post-event-callback re-frame.router/event-queue f))
|
||||
[id]
|
||||
(router/remove-post-event-callback re-frame.router/event-queue id))
|
||||
|
||||
|
||||
;; -- Helpful Message
|
||||
;; Assisting the v0.0.7 -> v0.0.8 tranistion. Remove in v0.0.9
|
||||
;; -- Deprecation Messages
|
||||
;; Assisting the v0.0.7 -> v0.0.8 tranistion.
|
||||
(defn register-handler
|
||||
[& args]
|
||||
(console :warn "re-frame: \"register-handler\" has been renamed \"reg-event\"")
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
|
||||
;; -- API
|
||||
(push [this event])
|
||||
(add-post-event-callback [this f])
|
||||
(add-post-event-callback [this id callack])
|
||||
(remove-post-event-callback [this f])
|
||||
|
||||
;; -- Implementation via a Finite State Machine
|
||||
|
@ -97,12 +97,14 @@
|
|||
(push [this event] ;; presumably called by dispatch
|
||||
(-fsm-trigger this :add-event event))
|
||||
|
||||
(add-post-event-callback [_ callback-fn]
|
||||
;; register a callback function which will be called after each event is processed
|
||||
(set! post-event-callback-fns (conj post-event-callback-fns callback-fn)))
|
||||
;; register a callback function which will be called after each event is processed
|
||||
(add-post-event-callback [_ id callback-fn]
|
||||
(->> (assoc post-event-callback-fns id callback-fn)
|
||||
(set! post-event-callback-fns)))
|
||||
|
||||
(remove-post-event-callback [_ callback-fn]
|
||||
(set! post-event-callback-fns (remove #(= % callback-fn) post-event-callback-fns)))
|
||||
(remove-post-event-callback [_ id]
|
||||
(->> (dissoc post-event-callback-fns id)
|
||||
(set! post-event-callback-fns)))
|
||||
|
||||
|
||||
;; -- FSM Implementation ---------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue