-
Notifications
You must be signed in to change notification settings - Fork 15
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
with-redefs + wrap-with macros #123
Conversation
src/state_flow/labs/state.clj
Outdated
runner# (state-flow/runner) | ||
:let [[ret# state#] (clojure.core/with-redefs ~bindings | ||
(runner# ~flow world#))]] | ||
(state/put state#) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(state/put state#) | |
(state-flow.api/swap-state (constantly state#)) |
:let [[ret# state#] (clojure.core/with-redefs ~bindings | ||
(runner# ~flow world#))]] | ||
(state/put state#) | ||
(state/return ret#))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(state/return ret#))) | |
(state-flow.api/return ret#))) |
I think if we're going to add this to state-flow proper (even in labs), I think we should add the (wrap-in (fn [wrapped-flow] (with-redefs [<bindings>] wrapped-flow))
flow-to-wrap)) |
src/state_flow/labs/state.clj
Outdated
|
||
(defmacro with-redefs | ||
[bindings flow] | ||
(assert *enable-with-redefs-macro* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the usage of this variable. Just a warning in the comments is fine. The flag looks like a handicap to me.
@@ -0,0 +1,19 @@ | |||
(ns state-flow.labs.state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would probably go better in another namespace. Maybe labs.helpers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it'd go along with the other state fns, like wrap-fn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine here, but we should have a docstring in this namespace that indicates that it is experimental and subject to change.
Background: #33 |
@dchelimsky from what I saw, #33 was closed because of the potential of misuse. If we limit this implementation to specific use cases we see the need for it, the misuse might be reduced, no? We can keep |
We can also leave it public for now in labs and check if this is going to be an issue |
[state-flow.state :as state])) | ||
|
||
(defmacro wrap-with | ||
"WARNING: `wrap-with` usage is not recommended. Use only if you know what you're |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning is fine, but we should also say what it does :-D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should say that this here to support helper macros like with-redefs
, and reference that as an implementation example.
(state/return ret#))) | ||
|
||
(defmacro with-redefs | ||
"WARNING: `with-redefs` usage is not recommended. Use only if you know what you're |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment - docstring should also say what this does, and warn that with-redefs
is not threadsafe.
test/state_flow/labs/state_test.clj
Outdated
(f)) | ||
|
||
(deftest wrap-with-test | ||
(testing "verify wrapper is called" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(testing "verify wrapper is called" | |
(testing "wrapper is called" |
test/state_flow/labs/state_test.clj
Outdated
(fn [f] (print "called it") (f)) | ||
(state/modify put2)) | ||
(state-flow/run {})))))) | ||
(testing "verify flow runs successfully" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(testing "verify flow runs successfully" | |
(testing "flow runs successfully" |
test/state_flow/labs/state_test.clj
Outdated
(state-flow/run {})))))) | ||
|
||
(deftest with-redefs-test | ||
(testing "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either fill in the docstring or bag testing
Thanks for all the updates @caioaao. I'm waiting for some feedback from other folks within Nubank. |
I have more issues with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now, but I want at least one other approval before merging.
Oh! There is one. I'm going to add a commit to update the changelog first. Then I'll merge it. |
I can't do that on your branch @caioaao so I'll do it in a follow up PR before releasing. |
No description provided.