Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Refactor #11

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .cljfmt.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:indents {k16.gx.beta.context/merge-err-ctx [[:inner 0]]
merge-err-ctx [[:inner 0]]

k16.gx.beta.context/with-ctx [[:inner 0]]
with-ctx [[:inner 0]]}}
33 changes: 33 additions & 0 deletions src/k16/gx/beta/context.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(ns k16.gx.beta.context)

(def ^:dynamic *runtime*
"GX's execution runtime, contains:
- :err is used for creating/throwing exceptions with contextual data
- :context contains gx context with configurations"
{:err {:error-type :general}
:context {}})

(defmacro merge-err-ctx
"Creates error context by merging value to :err in `k16.gx.beta.error/*runtime*`"
[err & body]
`(binding [~`*runtime* (update ~`*runtime* :err merge ~err)]
~@body))

(defmacro with-ctx
"Takes map with two keys :context and :err. Creates execution context"
[ctx & body]
`(binding [~`*runtime* (merge ~`*runtime* ~ctx)]
~@body))

(defn err []
(get *runtime* :err))

(defn context []
(get *runtime* :context))

(comment
(with-ctx {:context {:foo 1}}
*runtime*)
(merge-err-ctx {:node-key :foo}
(err))
)
Loading