https://github.com/jtkdvlp/re-frame-cookie-fx
A re-frame "effects handler" for storing data in cookies
https://github.com/jtkdvlp/re-frame-cookie-fx
cookies re-frame
Last synced: 10 months ago
JSON representation
A re-frame "effects handler" for storing data in cookies
- Host: GitHub
- URL: https://github.com/jtkdvlp/re-frame-cookie-fx
- Owner: jtkDvlp
- License: mit
- Created: 2017-09-15T11:33:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-23T18:53:29.000Z (over 5 years ago)
- Last Synced: 2025-03-04T11:42:44.092Z (11 months ago)
- Topics: cookies, re-frame
- Language: Clojure
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://clojars.org/jtk-dvlp/re-frame-cookie-fx)
[](https://github.com/jtkDvlp/re-frame-cookie-fx/blob/master/LICENSE)
# Cookie effect handler for re-frame
This [re-frame](https://github.com/Day8/re-frame) library contains an cookie [effect handler](https://github.com/Day8/re-frame/tree/develop/docs). The handler can be addressed by `:cookie` and uses the [goog.net.cookies](https://google.github.io/closure-library/api/goog.net.Cookies.html) API.
## Getting started
### Get it / add dependency
Add the following dependency to your `project.cljs`:
[](https://clojars.org/jtk-dvlp/re-frame-cookie-fx)
### Usage
See the following minimal code example or the [test.cljs](https://github.com/jtkDvlp/re-frame-cookie-fx/blob/master/test/re_frame_cookie_fx/test.cljs).
```clojure
(ns your.project
(:require [re-frame.core :as re-frame]
[re-frame-cookie-fx.core]))
(re-frame/reg-event-fx
:initialize
;; injects the cookie :re-frame-cookie-fx.core/db into your event handler
[(re-frame/inject-cofx :cookie)]
(fn [cofx _]
;; gets the current counter value from the cookie and / or creates it with the value 0
{:cookie (update (:cookie cofx) :counter (fnil identity 0))}))
```
## Appendix
I´d be thankful to receive patches, comments and constructive criticism.
Hope the package is useful :-)