-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created core namespace with base state management functions. Session
namespace refactoring. New release 0.1.4
- Loading branch information
1 parent
98f0e7b
commit 1408eab
Showing
4 changed files
with
24 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |