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
Add #send_back to the base controller
Add #send_back to the base controller #7
Conversation
lib/logux/base_controller.rb
Outdated
@@ -19,6 +19,10 @@ def initialize(action:, meta: {}) | |||
@meta = meta | |||
end | |||
|
|||
def send_back(action, meta = @meta) |
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.
We do not need to copy origin @meta
.
BaseController
is a controller to process action (an object with a description of what to change in a database). Each action has meta (with unique ID and time when it was created).
@action
and @meta
here is an action from the client, which we should process.
action
and meta
in send_back()
is an action, which server answer to client’s action.
By setting meta = @meta
we will force our server’s response action to have the same ID, that the client’s action had. Because the server’s action will have the same ID, the client will ignore this new server’s action, because of client already have action with the same ID.
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.
def send_back(action, meta = @meta) | |
def send_back(action, meta = { }) |
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.
Ok, got it now. So, I just take @meta
's client ID and add it to passed meta as clients
, to say Logux, that I want to send the action back to the client.
LGTM |
spec/logux/action_controller_spec.rb
Outdated
@@ -22,6 +21,23 @@ | |||
end | |||
end | |||
|
|||
describe '#send_back' do | |||
subject(:send_back) { action_controller.send_back(back_action) } |
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.
let's check the case passing a meta, to ensure a result of meta composition with merge
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.
Done. I suggested that checking both cases would be redundant, so I changed existing spec without meta passing instead of adding another one with passed meta. Let me know if I need to check both of these cases.
This PR relates to this issue and this post.
Should the issue be here, in this repo?
I hope, I understand this task correctly, let me know if something is wrong.