Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/federkasten/rhythm
[Obsolete Project] A ClojureScript library handling states and actions for event-driven programming
https://github.com/federkasten/rhythm
Last synced: 22 days ago
JSON representation
[Obsolete Project] A ClojureScript library handling states and actions for event-driven programming
- Host: GitHub
- URL: https://github.com/federkasten/rhythm
- Owner: federkasten
- License: apache-2.0
- Created: 2014-05-28T10:11:38.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-10-30T08:52:42.000Z (about 10 years ago)
- Last Synced: 2023-06-08T03:35:14.648Z (over 1 year ago)
- Language: Clojure
- Homepage:
- Size: 266 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rhythm
A ClojureScript library handling states and actions for event-driven programming
## Usage
Add the following dependency to your `project.clj`:
```
[rhythm "0.1.1-SNAPSHOT"]
```### Setup actor
```clj
(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"))})))
```### Watch state
To add watcher
```clj
(watch-state! example-actor :done
{:in (fn [key]
(.log js/console "Done!")
:out (fn [key]
(.log js/console "Next!"))
```To remove watcher
```clj
(unwatch-state! example-actor :done)
```### Trigger action
```clj
(trigger-action! example-actor :load)
```## License
Copyright 2014 [Takashi AOKI][tak.sh]
Licensed under the [Apache License, Version 2.0][apache-license-2.0].
[tak.sh]: http://tak.sh
[apache-license-2.0]: http://www.apache.org/licenses/LICENSE-2.0.html