Surgical DOM Updates with StimulusReflex
# app/reflexes/examples_reflex.rb | |
class ExamplesReflex < ApplicationReflex | |
include CableReady::Broadcaster | |
before_reflex :surgical_update, only: [:noop] | |
def surgical_update | |
cable_ready["example"].inner_html( | |
selector: "#example-container", | |
html: ExampleController.render( | |
partial: "/examples/list_item", | |
assigns: {item: Item.find(element.dataset[:id])} | |
) | |
) | |
cable_ready.broadcast | |
throw :abort | |
end | |
def noop | |
# we will never hit this because we throw :abort in before_reflex | |
end | |
end |
<!-- app/views/examples/show.html.erb --> | |
<a href="#" data-reflex="click->ExampleReflex#noop">Fetch Data</a> | |
<div id="example-container"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment