https://github.com/brianium/action
A dumb simple message format inspired by flux standard actions
https://github.com/brianium/action
clojure clojurescript flux
Last synced: 10 months ago
JSON representation
A dumb simple message format inspired by flux standard actions
- Host: GitHub
- URL: https://github.com/brianium/action
- Owner: brianium
- License: mit
- Created: 2017-08-21T19:32:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-21T19:37:55.000Z (over 8 years ago)
- Last Synced: 2025-03-18T05:56:26.446Z (10 months ago)
- Topics: clojure, clojurescript, flux
- Language: Clojure
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# action
[](https://clojars.org/brianium/action)
A simple message format modeled after [flux standard actions](https://github.com/acdlite/flux-standard-action).
For Clojure and ClojureScript.
## Usage
The spec should sort out what an action is :)
```clojure
(s/def ::type keyword?)
(s/def ::payload any?)
(s/def ::error? boolean?)
(s/def ::meta any?)
(s/def ::action (s/keys :req-un [::type]
:opt-un [::payload ::error? ::meta]))
```
An example of an action:
```clojure
{:type :create/user
:error? false
:paylaod {:name "Brian" :title "Computer"}}
```
A couple of functions are bundled to facilitate use of this format.
```clojure
(require '[brianium.action :refer [make-action make-error]])
(make-action :create/user {:name "Brian" :title "Computer"} false)
;; => {:type :create/user
:payload {:name "Brian" :title "Computer"}
:error? false}
(make-action :create/user {:name "Brian" :title "Computer"})
;; => {:type :create/user
:payload {:name "Brian" :title "Computer"}
:error? false}
(make-action :cache-clear)
;; => {:type :cache-clear
:payload {}
:error? false}
(make-error :create/user (ex-info "User creation error" {:reason "email exists"}))
;; => {:type :create/user
:payload ,, (IExceptionInfo instance)
:error? true}
```
## Testing
```
lein test
```