Skip to content

Commit faf1275

Browse files
kennethkalmersuperstructor
authored andcommitted
chore: update README
1 parent 1af9c39 commit faf1275

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,35 @@ like:
188188
:failure :timeout}
189189
```
190190

191+
### Optional: Handler for :on-request
192+
193+
If you need access to the raw request, to for example, cancel long running requests or repeated debounced requests,
194+
you can pass an `:on-request` handler that will be called with the request.
195+
196+
```clojure
197+
(re-frame/reg-event-fx
198+
::http-post
199+
(fn [_world [_ val]]
200+
{:http-xhrio {:method :get
201+
:uri "https://httpbin.org/delay/60"
202+
:format (ajax/json-request-format)
203+
:response-format (ajax/json-response-format {:keywords? true})
204+
:on-request [::track-slow-request "my-request"]
205+
:on-success [::success-get-result]
206+
:on-failure [::failure-get-result]}}))
207+
208+
(reg-event-db
209+
::track-slow-request
210+
(fn [db [_ my-id xhrio]]
211+
(assoc-in db [:requests my-id] xhrio)))
212+
```
213+
214+
Later if you need to, you could retrieve the request from the app-db and cancel it.
215+
216+
**N.B.**: To prevent memory leaks you need to cleanup the request in both your `:on-success` and `:on-failure` handlers.
217+
Otherwise the requests will just hang around in your app-db indefinitely.
218+
219+
191220
### Tip
192221

193222
If you need additional arguments or identifying tokens in your handler, then

0 commit comments

Comments
 (0)