Oh cookie, yummy! - KVN, Final Space
Herein a re-frame "Effects Handler", which enables various cookie operations using goog.net.Cookies.
Note: Due to recent breaking changes to ClojureScript 1.9's use of spec, version 0.0.2 of this library requires that you use ClojureScript 1.9.542 or later
In the namespace where you register your event handlers, prehaps called
handlers.cljs
, you have two things to do:
First, add this require
to the ns
:
(ns app.handlers
(:require
...
[com.github.lockie.re-frame-cookie-fx] ;; <-- add this
...))
Second, write an event handler which uses this effect:
(reg-event-fx
:handler-with-cookies
(fn [{:keys [db]} _]
{:cookie/set {:name "cookie-monster-says"
:value "Om Nom Nom Nom!"}}))
Other supported effects include the below which are documented in the source:
:cookie/remove
:cookie/clear
Besides :name
and :value
, you can supply :on-success
and :on-failure
handlers as
well as the usual cookie options including :max-age
, :path
, :domain
, and
:secure
. See details and documentation in the source.
To use a coeffect:
(reg-event-fx
:handler-with-cookie-cofx
[(inject-cofx :cookie/get [:cookie-monster-says])]
(fn [{db :db cookies :cookie/get} _]
...
Other supported coeffects include the below which are documented in the source:
:cookie/enabled?
:cookie/empty?
:cookie/keys
:cookie/values
:cookie/count
Copyright © 2016 SMX Ltd.
Distributed under the Eclipse Public License, the same as Clojure.
Can you improve this documentation? These fine people already did:
Andrew Kravchuk, David Goldfarb & Isaac JohnstonEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close