A ClojureScript library handling states and actions for event-driven programming
Add the following dependency to your project.clj
:
[rhythm "0.1.1-SNAPSHOT"]
(let [example-actor (actor "loading-example" {:state [:waiting]})]
(-> example-actor
(add-action :load
(fn [f]
(switch-state! a :waiting :loading)
;; some heavy processing
(js/setTimeout (fn [e] (switch-state! :loading :done)) 10000)))
(add-state [:done :error]
{:in (fn []
(js/setTimeout #(switch-state! a :done :waiting) 100))
:out (fn []
(.log js/console "Reset actor to waiting"))})))
To add watcher
(watch-state! example-actor :done
{:in (fn [key]
(.log js/console "Done!")
:out (fn [key]
(.log js/console "Next!"))
To remove watcher
(unwatch-state! example-actor :done)
(trigger-action! example-actor :load)
Copyright 2014 Takashi AOKI
Licensed under the Apache License, Version 2.0.