-
Notifications
You must be signed in to change notification settings - Fork 67
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
Hooks are invoked only on the first call #153
Comments
Thank you for reporting it! I added this spec to verify this issue. The The problem is that the callback is saved under the |
I started thinking about this. One way to solve this is to save the action specific callbacks in the current thread, something like this: Thread.current[:some_action_callbacks] = [proc1, proc2] That way we could keep those callbacks around for multiple calls. Thoughts? |
@adomokos sorry for not answering, been busy 😞 First I should sort out a whole architecture, and then maybe I would be able to suggest something 😄 |
Quick (and therefore maybe stupid) question: why we should nullify |
Hello, I was trying to use Maybe there should be a distinction between "static" callbacks and the current dynamic behavior. Also, it seems the I will use |
I added the @klamontagne - is your issue similar to the one described in #152? |
@adomokos I've got a quick idea: It seems that now there is no link back to the organizer from the action. How about incorporate it? With that, we'll be able to access callbacks from actions independently from context. So then we can stop nullify For me storing callbacks in context feels unnatural, like the fact that actions invoke callbacks. I believe, it should be the organizer's job, and organizer should know about callbacks, not actions themselves. It's just my general thoughts after the quick run through the code. What do you think about it? |
The reason I added it to the context is the fact that the Context carries the state of information, Actions are only behavior, Organizers are assembling the actions in the right order. I am not a big fan of adding the callbacks to the I need to think about this a bit more, maybe start a PR myself so you and others could comment on. I'll try to do it next week, when I'll be back in work-mode again. If you have ideas on how to improve it, feel free to begin a PR and submit it early, so I could give you directions on where we should go with it. I'd hate to see you working on something for days/weeks and not merging it in the end. Thanks! |
Thank you for your reply @adomokos!
These two points again lead me to the already expressed idea of moving callbacks invocation to Organizer or Reducer :) Therefore Organizer will have more control on actions flow (because callbacks are part of it), and Actions will have less knowledge about surroundings I'll try to code something on the weekend but unfortunately can't guarantee it |
Yeah, this week is tough for me to put any serious effort into it. 2nd half of next week seems to be better. |
I recommend using RequestStore rather than Thread.current for saving this state, as it plays nicely with threaded servers. |
That is great, thank you for suggesting it. However, that would add a dependency on rack and my heart already bleeds that LightService has dependency on ActiveSupport. I'd much rather just remove the whole |
I mean you could make the rails part a separate gem that ties into this one, that overrides what it uses in a gem config variable. Or alternatively make sure you reset the Thread.current variables after it's finished executing so nothing persists longer than it should. |
Submit a PR, and I'll think about it ;-). |
Hello!
Today I stumbled upon some strange issue. It seems that hooks (in my case
after_actions
) are invoked only on the first.call
.Here is, how my method
call
looks like in theOrganizer
class:And in the
Organizer.with
I saw this:light-service/lib/light-service/organizer.rb
Lines 19 to 31 in 2656002
So after first
with
call we setdata[:_after_actions]
properly, and then we nullify@after_actions
. And it never came back, because ofMacros.after_actions
won't be called again. So on the next invocations ofwith
,data[:_after_actions]
won't be set.Am I misunderstanding something here?
The text was updated successfully, but these errors were encountered: