Skip to content

Commit

Permalink
Created core namespace with base state management functions. Session
Browse files Browse the repository at this point in the history
namespace refactoring. New release 0.1.4
  • Loading branch information
markostanimirovic committed Jul 30, 2019
1 parent 98f0e7b commit 1408eab
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject org.clojars.stanimirovic/re-action "0.1.3"
(defproject org.clojars.stanimirovic/re-action "0.1.4"
:description "ClojureScript Framework for Building Single Page Applications"
:url "https://github.com/stanimirovic/re-action"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand Down
16 changes: 16 additions & 0 deletions src/re_action/core.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(ns re-action.core
(:require [re-streamer.core :as re-streamer :refer [subscribe emit]]))

(defn store [state]
(re-streamer/behavior-stream state))

(defn select [store & keys]
(-> store
(re-streamer/pluck keys)
(re-streamer/distinct =)))

(defn update-state! [store state]
(emit store state))

(defn patch-state! [store partial-state]
(update-state! store (into @(:state store) partial-state)))
3 changes: 2 additions & 1 deletion src/re_action/router.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@
(throw (js/Error (str "Route: " path " is not defined"))))]
(emit store route)))

(defn start [] (navigate (.. js/window -location -hash)))
(defn start []
(navigate (.. js/window -location -hash)))
14 changes: 5 additions & 9 deletions src/re_action/session.cljs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
(ns re-action.session
(:require [re-streamer.core :as re-streamer :refer [emit]]))
(:require [re-action.core :refer [store select select-distinct patch-state!]])
(:refer-clojure :exclude [get]))

(defonce ^:private store (re-streamer/behavior-stream))
(defonce ^:private session (store {}))

(defn put! [key value]
(emit store (assoc @(:state store) key value)))
(patch-state! session {key value}))

(defn get [key]
(key @(:state store)))

(defn get-s [key]
(-> store
(re-streamer/map key)
(re-streamer/distinct =)))
(select-distinct session key))

0 comments on commit 1408eab

Please sign in to comment.