Skip to content

Instantly share code, notes, and snippets.

@jeaye

jeaye/flow.cljs Secret

Last active November 5, 2017 02:13
Show Gist options
  • Save jeaye/db469d6fb0709a5498863b747cd48a89 to your computer and use it in GitHub Desktop.
Save jeaye/db469d6fb0709a5498863b747cd48a89 to your computer and use it in GitHub Desktop.
(def boot-flow
{:id ::boot
:first-dispatch [::login.events/do-load-credentials]
; Credentials can be loaded or acquired from showing a login.
:rules [{:when :seen-any-of?
:events [::login.events/fail-load-credentials
::http.events/error-403]
; If there are no saved credentials, we have to show a login.
:dispatch [::login.events/do-show-login]}
{:when :seen-any-of?
:events [::login.events/success-load-credentials
::login.events/success-show-login]
; Once we have credentials, touch the server.
:dispatch-n [[::login.events/save-credentials] ; Success doesn't matter.
[::login.events/do-touch]]}
; TODO: Unfortunately, do-touch may give an HTTP 403. This can happen
; if the loaded credentials were expired on invalid. In this case, I
; want the flow to jump back to the first rule.
{:when :seen?
:events ::login.events/success-touch
:dispatch [::success-boot]
:halt? true}
{:when :seen-any-of?
:events [::login.events/fail-show-login
::login.events/fail-touch]
:dispatch [::fail-boot]
:halt? true}]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment