Skip to content

Comments

MOVED: updates-for should respect url and only params on each element#182

Closed
leastbad wants to merge 2 commits intostimulusreflex:masterfrom
leastbad:updates_for_updates_for
Closed

MOVED: updates-for should respect url and only params on each element#182
leastbad wants to merge 2 commits intostimulusreflex:masterfrom
leastbad:updates_for_updates_for

Conversation

@leastbad
Copy link
Contributor

@leastbad leastbad commented Feb 13, 2022

This was moved to #186.

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: "[email protected]"
post.update name: "Frederick" # updates the first three blocks, plus console warning
post.update email: "[email protected]" # 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 13, 2022
@leastbad leastbad added this to the 5.0 milestone Feb 13, 2022
Copy link
Contributor

@julianrubisch julianrubisch left a comment

Choose a reason for hiding this comment

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

A first set of comments... Also, I'd love to know why the dev builds job failed, because I'd love to test this against an app I have here... @marcoroth any idea ?

@leastbad
Copy link
Contributor Author

In the interim, I've had good luck running yarn run watch and then pointing my packages.json dependencies at "link:/home/leastbad/cable_ready/dist/cable_ready.umd.js".

@leastbad leastbad closed this Feb 15, 2022
@leastbad leastbad changed the title updates-for should respect url and only params on each element MOVED: updates-for should respect url and only params on each element Feb 15, 2022
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.

2 participants