-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Include changeset in class-level updates broadcast #193
Conversation
Enables using the :only option with updates_for to filter updates when subscribing to all instances of a model class. Fixes stimulusreflex#192
Okay I expected that test failure, that's okay. There also don't seem to be any tests for this behavior yet which is an omission on our part. I'll write some tests for this soonish. The feature itself looks sensible, though I'd also like to ask @andrewerlanger for his opinion since he originally proposed this feature and maybe has a fresher memory of things than me. |
@julianrubisch I'm not sure what you mean by "There also don't seem to be any tests for this behavior yet". I looked at the test failures, and they were mostly/all tests for this behavior, so I've updated the expectations. |
Sorry for being unclear - I meant there's currently no tests for a specific case testing the I'd still love for @andrewerlanger to check back on this in a spare minute to make sure I don't miss something! |
@grncdr thanks very much for taking this on 🙏 The code itself looks good to me, I'm just not sure whether the following is true:
As far as I understand: when passing a class constant to If that is indeed the case, it would mean that the changes introduced in this PR do the following for the code below: <%= updates_for Item, only: :title do %>
<% items.each do |item| %>
<p><%= item.title %></p>
<% end %>
<% end %>
From the PR description, it sounds to me like that last point is the important one. If you update an item's I could very well be wrong about this though, so all the more reason to add some tests :) |
Thanks for checking this out @andrewerlanger 👍
There's some confusion here about what problem this PR is actually solving, probably because I didn't include the issue description from #192 here. My issue is not that updates were being missed, but that updates_for was causing (many) reloads for updates that were uninteresting. Sticking with the Edit: given this explanation, I can attest that these changes do work as described, because I've been using a monkey-patch version of this in production since I opened the original issue. |
What follows is a lot of pedantic clarification, feel free to skip it if we're already on the same page.
That is not the case. If the model class contains cable_ready/app/models/concerns/cable_ready/updatable/model_updatable_callbacks.rb Lines 22 to 25 in 50ffe49
The cable_ready/javascript/elements/updates_for_element.js Lines 190 to 199 in 50ffe49
Regarding the scenarios you described:
The broadcasting of updates for items being created (or destroyed) goes through a different code path, calling
This is also incorrect, the list will be refreshed, both in the current version and in the version including my changes. However, if some other attribute of the Item is updated, the list will be refreshed in the current version, and won't be refreshed after my PR. All this PR does is add a little more information to that existing broadcast so that the |
@grncdr thanks for clarifying, it sounds like I was wrong in that case. I thought something like If, as you suggest, all items are indeed being updated for uninteresting updates, then I fully agree it would be useful to opt out of these. That was also my motivation for proposing an Appreciate you taking the time to explain this in detail. Everything looks good to me with the help of that context (although with the minor caveat that I haven't had a chance to test it myself yet). @julianrubisch @leastbad what do you think? |
Thanks @grncdr for the detailed rundown. 💚 I admit that even though writing most of it I'm sometimes fuzzy wrt the code paths at play. That part is also hard to test because it involves an interaction of backend and frontend code. I will reserve some time soon to write a couple of JavaScript tests that should hopefully clear things up for the next time I need to look at it 😬 |
Enables using the :only option with updates_for to filter updates when subscribing to all instances of a model class.
Fixes #192