Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:seancorfield/engine
Browse files Browse the repository at this point in the history
Merge beta4 (state path accessor) to intuitive apply, and bump to 0.1.0
  • Loading branch information
seancorfield committed Sep 21, 2016
2 parents 0f3a4bc + 3f3a456 commit b8c6883
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/engine/core.clj
Expand Up @@ -18,8 +18,10 @@
"Commit updates/deletes and yield nil or the failure (if any).")
(return [this value]
"Set/replace the result this engine will return on a commit!")
(state [this]
(-state [this path]
"Yield the current state -- the result that would be returned.
If path is not nil, assume state is navigable via that path and
return just that part.
If the engine is in failure mode, return nil.")
(-transform [this f args]
"Transform the result this engine will return on a commit!
Expand Down Expand Up @@ -82,8 +84,9 @@
;; happy path workflow
(return [this value]
(if failure this (assoc this :result value)))
(state [this]
(when-not failure result))
(-state [this path]
(when-not failure
(if path (get-in result path) result)))
(-transform [this f args]
(if failure this ($/apply update-in this [:result] f args)))
(-apply [this f args]
Expand Down Expand Up @@ -153,6 +156,11 @@
[this & args]
(-query this args))

(defn state
"Adapter for 2-arity -state."
[this & args]
(-state this args))

(defn transform
"Adapter for 3-arity -transform."
[this f & args]
Expand Down
8 changes: 7 additions & 1 deletion test/engine/core_test.clj
Expand Up @@ -84,7 +84,7 @@
(return "> 13"))
(commit!)))

(expect "some : output\n"
(expect #"some : output\r?\n"
(with-out-str
(-> (engine {:out (c/insertable-store
[_ label value]
Expand Down Expand Up @@ -115,3 +115,9 @@
(transform e #(+ % a b c d)))
[1 2 3 4])
(commit!)))

(expect :ok
(-> (engine {})
(return {:a {:b {:c [:bad :ok]}}})
(as-> e (return e (state e :a :b :c 1)))
(commit!)))

0 comments on commit b8c6883

Please sign in to comment.