Skip to content

Commit

Permalink
Make low-level state* function public and documented
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnout Roemers committed Jul 7, 2020
1 parent 4f92ddf commit 1643b19
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.0.1

### Added

- The low-level `state*` function is now public and documented.

## 1.0.0

Initial release
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

5 changes: 2 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(defproject functionalbytes/redelay "1.0.0"
(defproject functionalbytes/redelay "1.0.1"
:description "Clojure library for first class lifecycle-managed state."
:url "https://github.com/aroemers/redelay"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.10.1"]]
:repl-options {:init-ns redelay.core}
:plugins [[lein-codox "0.10.7"]])
:repl-options {:init-ns redelay.core})
21 changes: 13 additions & 8 deletions src/redelay/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@
:not-delivered)]
(str "#<State@" addr "[" name "]: " val ">"))))

(defn ^:no-doc state*
[ns-str? name-str? start-fn stop-fn meta]
(let [name (symbol ns-str? (or name-str? (str (gensym "state--"))))]
(defn state*
"Low-level function to create a State object. All keys are optional.
The `:start-fn` value must be a 0-arity function. The `:stop-fn`
value must be a 1-arity function. The `:meta` value must be a map."
[{:keys [ns-str name-str start-fn stop-fn meta]
:or {start-fn (fn [])
stof-fn (fn [_])}}]
(let [name (symbol ns-str (or name-str (str (gensym "state--"))))]
(with-meta (State. name start-fn stop-fn (atom unrealized) nil)
meta)))

Expand Down Expand Up @@ -111,11 +116,11 @@
name (first names)
meta (first metas)]
(assert (or (nil? name) (symbol? name)) "name must be symbol")
`(state* ~(if name (namespace name) (str *ns*))
~(when name (clojure.core/name name))
(fn [] ~@start)
(fn [~'this] ~@stop)
~meta))))
`(state* {:ns-str ~(if name (namespace name) (str *ns*))
:name-str ~(when name (clojure.core/name name))
:start-fn (fn [] ~@start)
:stop-fn (fn [~'this] ~@stop)
:meta ~meta}))))

(defn state?
"Returns true if obj is a State object."
Expand Down

0 comments on commit 1643b19

Please sign in to comment.