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

updates-for should respect url and only params on each element #186

Merged
merged 1 commit into from
Feb 15, 2022

Conversation

leastbad
Copy link
Contributor

This PR used to be #182.

Reworked updates-for element to allow per-block url and only attributes. URL fragment indexes are now tracked on a per-URL basis.

That means the following contrived example works as you'd expect:

index.html.erb

<%= updates_for current_user, :posts do %>
  <% Post.all.each do |p| %>
    <p><%= p.name %>, <%= p.email %></p>
  <% end %>
  <p><%= rand(1..1000) %></p>
<% end %>

<%= updates_for current_user, :posts, only: [:name] do %>
  <% Post.all.each do |p| %>
    <p><%= p.name %>, <%= p.email %></p>
  <% end %>
  <p><%= rand(1..1000) %></p>
<% end %>

<%= updates_for current_user, :posts, url: "/updates_for" do %>
  <% Post.all.each do |p| %>
    <p><%= p.name %>, <%= p.email %></p>
  <% end %>
  <p><%= rand(1..1000) %></p>
<% end %>

<%= updates_for current_user, :posts, only: [:name], url: "/updates_for" do %>
  <% Post.all.each do |p| %>
    <p><%= p.name %>, <%= p.email %></p>
  <% end %>
  <p><%= rand(1..1000) %></p>
<% end %>

updates_for.html.erb

<%= updates_for current_user, :posts do %>
  <p>HAIRY!</p>
  <p><%= rand(1..1000) %></p>
<% end %>

No, I don't know why Post has a name and email. Don't ask hard questions.

post = current_user.posts.create name: "Fred", email: "fred@gmail.com"
post.update name: "Frederick" # updates the first three blocks, plus console warning
post.update email: "frederick@gmail.com" # updates only the first and third

Note that the 4th block will not be updated because updates_for.html.erb only has one block; a warning is generated in the console to suggest that there wasn't enough elements for the update to complete.

Unfortunately this will certainly clash with #181 as written, although I have done my best to maintain the general structure and naming to ease merge conflicts.

@leastbad leastbad added enhancement javascript Pull requests that update Javascript code labels Feb 15, 2022
@leastbad leastbad added this to the 5.0 milestone Feb 15, 2022
- reworked updates-for element to allow per-block url and only attributes

- created blocks getter and renamed ignoresInnerUpdates
@marcoroth
Copy link
Member

This PR is now published as a dev-build. To use it to your project, run:

yarn add cable_ready@https://github.com/cableready/dev-builds/archive/cable_ready/07da548.tar.gz

@leastbad leastbad merged commit bea2397 into master Feb 15, 2022
@leastbad leastbad deleted the updates_for_updates_for branch February 15, 2022 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants