Skip to content

Instantly share code, notes, and snippets.

@janherich
Last active April 20, 2018 06:23
Show Gist options
  • Save janherich/8ea1cff5dd7e79acf6ac034003d24c05 to your computer and use it in GitHub Desktop.
Save janherich/8ea1cff5dd7e79acf6ac034003d24c05 to your computer and use it in GitHub Desktop.
Extension - events
;; 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
Copy link
Author

add-http-request and set-in are function creators (external consumers doesn't have to know about it at all) because we will combine them to register real re-frame event by the handlers/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:

  • your function will be always called with one argument representing state (we will decide if it will be app db, subpath related to extension , etc.)
  • your function has to return new state (again it could be just extension subpath, etc.)

@jeluard
Copy link

jeluard commented Apr 20, 2018

@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