Skip to content

Commit b770929

Browse files
authored
Merge pull request #11 from technomancy/custom-handlers
Allow for extensible responses using monroe-custom-handlers.
2 parents 3aecaf7 + 92831ca commit b770929

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

monroe.el

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ but will NOT work on ClojureScript. This option assumes 'monroe-detail-stacktrac
8787
(defvar monroe-requests-counter 0
8888
"Serial number for message.")
8989

90+
(defvar monroe-custom-handlers (make-hash-table :test 'equal)
91+
"Map of handlers for custom ops.")
92+
9093
(defvar monroe-repl-buffer "*monroe*"
9194
"Name of nREPL buffer.")
9295

@@ -271,12 +274,13 @@ history purposes."
271274
(kill-buffer (process-buffer process))
272275
(monroe-disconnect))
273276

274-
(defun monroe-dispatch (response)
275-
"Find response id and call associated callback."
276-
(monroe-dbind-response response (id)
277-
(let ((callback (gethash id monroe-requests)))
278-
(when callback
279-
(funcall callback response)))))
277+
(defun monroe-dispatch (msg)
278+
"Find associated callback for a message by id or by op."
279+
(monroe-dbind-response msg (id op)
280+
(let ((callback (or (gethash id monroe-requests)
281+
(gethash op monroe-custom-handlers))))
282+
(when callback
283+
(funcall callback msg)))))
280284

281285
(defun monroe-net-decode ()
282286
"Decode the data in the current buffer and remove the processed data from the

0 commit comments

Comments
 (0)