Last active
April 20, 2018 06:23
-
-
Save janherich/8ea1cff5dd7e79acf6ac034003d24c05 to your computer and use it in GitHub Desktop.
Extension - events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; examples of public functions provided by us | |
(defn add-http-request [{:keys [url method payload]}] | |
(fn [_] | |
{:http {:method method | |
:url url | |
:payload payload}})) | |
(defn set-in [{:keys [path value]}] | |
(fn [_] | |
{:db (set-in db path value)})) | |
{:status/add-http-request add-http-request | |
:status/set-in set-in} | |
;; hypotetical usage | |
:views/my-component | |
[button {:on-press #event [::send-transaction [:status/add-http-request {:url "/transactions" | |
:method "post" | |
:payload "test"}] | |
[:status/set-in {:path [:extension :sent] | |
:value true}]]} | |
"Click me!"] |
@janherich What's send-transaction
in this context and how does it manipulates both add-http-request
and set-in
?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add-http-request
andset-in
are function creators (external consumers doesn't have to know about it at all) because we will combine them to register realre-frame
event by thehandlers/merge-fx
macro which always expects functions taking (at least) cofx argument and returning map of effects.In case we will want to provide our consumers way to define event handling functions by themselves, we can specify following function interface (in javascript) to adhere to: