-
Notifications
You must be signed in to change notification settings - Fork 428
Selector-based replace #616
Comments
Hi @firedev, In the Turbolinks docs, there is a concept of namespaced ids, maybe you can use it instead of CSS class?
<div id="comments:1"></div>
<div id="comments:2"></div>
<!-- ... -->
<div id="comments:12"></div> Cheers, |
Yep, that is the problem. I don't have the luxury of React that keeps track of it's components and can't do cycle in rails for obvious reasons. All in all
This way I don't have to worry about updating the wrong fragment and if there are more than one - no problem. |
Sorry, I don't really understand what you said. If you use In a Rails console: comment = Comment.first
helper.dom_id(comment)
=> "comment_2"
helper.dom_id(comment, 'comments:')
=> "comments:_comment_2" The generated Then, when you run this Javascript command: Turbolinks.replace('some HTML tags', {change: 'comments'}); Turbolinks will replace all the HTML nodes with an id beginning with this string: |
I render the same fragment in a few places on the page, I can't generate Rails is going backwards here. Imagine each fragment is very expensive to compute, pre-rendederd and cached and I can't change id for each instance. What about russian-doll caching? |
Why do you render the same fragment in a few places of the page? |
I am building a worktime calendar app, there are few stats cells on each end, there are day cells you can edit in a modal window and they are being updated on-the-fly. Just remembers that this came up before and I was asking on StackOverflow: http://stackoverflow.com/questions/25418379/storing-object-id-in-html-document-id-vs-data-id-vs Apparently there are cases when you want more than one kind of the same object on the page. |
Well, maybe you can do something like that: class Comment < ActiveRecord::Base
attr_accessor :context_id
def to_key
super << @context_id
end
end Where |
Or monkey patching the comment = Comment.first
dom_id(comment, 'comments:', 1)
=> "comments:_comment_2_1" |
I'll just rename the title to a more general 'selector-based' replacement, so it allows more freedom of speech. |
Hi,
After working a bit with
Cells
andTrailblazer
I have adopted some concepts from React.js and built view-less system where updates are happening from the controller. It looks a bit like Turbolinks3:update_cells
just callsupdate
method on eachconcept
and glues the resulting JavaScripts together:Each cell has it's unique-ish document identifier, but instead of
id
I use unique CSSclass
.Why?
That allows me to do sweeping updates on the page. When one cell is changed, it is being re-rendered everywhere in the document. And the only thing that stops me from jumping on Turbolinks3 train is that Turbolinks uses
id
.Is there a way to replace document fragments based on CSS
class
? Was it even considered? Why not?Thanks.
The text was updated successfully, but these errors were encountered: