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

with-redefs + wrap-with macros #123

Merged
merged 6 commits into from
May 21, 2020
Merged

with-redefs + wrap-with macros #123

merged 6 commits into from
May 21, 2020

Conversation

caioaao
Copy link
Contributor

@caioaao caioaao commented May 18, 2020

No description provided.

runner# (state-flow/runner)
:let [[ret# state#] (clojure.core/with-redefs ~bindings
(runner# ~flow world#))]]
(state/put state#)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(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#)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(state/return ret#)))
(state-flow.api/return ret#)))

@dchelimsky
Copy link
Contributor

I think if we're going to add this to state-flow proper (even in labs), I think we should add the wrap-in generalization. The you could use e.g.

(wrap-in (fn [wrapped-flow] (with-redefs [<bindings>] wrapped-flow))
         flow-to-wrap))


(defmacro with-redefs
[bindings flow]
(assert *enable-with-redefs-macro*
Copy link
Collaborator

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
Copy link
Collaborator

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

@dchelimsky
Copy link
Contributor

I think if we're going to add this to state-flow proper (even in labs), I think we should add the wrap-in generalization.

Background: #33

@caioaao
Copy link
Contributor Author

caioaao commented May 20, 2020

I think if we're going to add this to state-flow proper (even in labs), I think we should add the wrap-in generalization.

@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 wrap-with but as a private function

@caioaao
Copy link
Contributor Author

caioaao commented May 20, 2020

We can also leave it public for now in labs and check if this is going to be an issue

@caioaao caioaao changed the title [PoC] with-redefs helper for state-flow with feature-flag for extra protection against misuse with-redefs + wrap-with macros May 21, 2020
@caioaao caioaao requested review from dchelimsky and sovelten May 21, 2020 00:12
[state-flow.state :as state]))

(defmacro wrap-with
"WARNING: `wrap-with` usage is not recommended. Use only if you know what you're
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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.

(f))

(deftest wrap-with-test
(testing "verify wrapper is called"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(testing "verify wrapper is called"
(testing "wrapper is called"

(fn [f] (print "called it") (f))
(state/modify put2))
(state-flow/run {}))))))
(testing "verify flow runs successfully"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(testing "verify flow runs successfully"
(testing "flow runs successfully"

(state-flow/run {}))))))

(deftest with-redefs-test
(testing ""
Copy link
Contributor

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

@dchelimsky
Copy link
Contributor

Thanks for all the updates @caioaao. I'm waiting for some feedback from other folks within Nubank.

@fernando-nubank
Copy link
Contributor

We can also leave it public for now in labs and check if this is going to be an issue

I have more issues with with-redefs than with wrap-fn but, as both of them are in labs I think they can be public.

Copy link
Contributor

@dchelimsky dchelimsky left a 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.

@dchelimsky
Copy link
Contributor

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.

@dchelimsky
Copy link
Contributor

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.

@dchelimsky dchelimsky merged commit 73ce48f into nubank:master May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants