Class: Phlex::Reactive::Reply
- Inherits:
-
Object
- Object
- Phlex::Reactive::Reply
- Defined in:
- lib/phlex/reactive/reply.rb
Overview
A component-bound facade over Response — the surface an action body uses to control its reply. Component#reply returns one, so an action writes
reply.replace.flash(:error, msg)
instead of
Phlex::Reactive::Response.replace(self).flash(:error, msg)
Two warts disappear: there is no constant to qualify (reply is a method, resolved on the component — so a namespaced component needs no ‘Response = …` alias) and no `self` to thread (the component is bound).
Reply is NOT a Response and does NOT subclass one: each verb forwards to the Response class method, supplying the bound component as the subject, and returns the real, frozen Response value the endpoint already honors. So immutability, chaining (.flash/.stream/.also_update/.also_replace), and render_self? are inherited untouched — and there is no “verb after a chained Response” asymmetry, because the chain is plain Response all the way down.
Response remains the public value object (it’s what the endpoint reads); it is simply an internal detail you rarely name directly now.
Instance Method Summary collapse
-
#initialize(component) ⇒ Reply
constructor
A new instance of Reply.
-
#morph ⇒ Object
Re-render in place via Idiomorph (method=“morph”) — keeps focus + caret.
-
#redirect(url) ⇒ Object
Client-side full navigation (Turbo.visit).
-
#remove ⇒ Object
Remove the component’s element from the DOM (render_self false).
-
#replace(morph: false) ⇒ Object
Re-render in place.
-
#streams(*strings) ⇒ Object
Self-targeting again: emit exactly these streams with a TOKEN-ONLY refresh (issue #30) — partial/per-field update, NO full-self replace, so the component’s live inputs survive.
-
#update ⇒ Object
Morph only inner HTML (preserves the root element + its token attr).
-
#with(*strings) ⇒ Object
Escape hatch / multi-stream root: zero or more raw turbo-stream strings.
Constructor Details
#initialize(component) ⇒ Reply
Returns a new instance of Reply.
28 29 30 |
# File 'lib/phlex/reactive/reply.rb', line 28 def initialize(component) @component = component end |
Instance Method Details
#morph ⇒ Object
Re-render in place via Idiomorph (method=“morph”) — keeps focus + caret.
41 42 43 |
# File 'lib/phlex/reactive/reply.rb', line 41 def morph Response.morph(@component) end |
#redirect(url) ⇒ Object
Client-side full navigation (Turbo.visit). Pass a *_url.
58 59 60 |
# File 'lib/phlex/reactive/reply.rb', line 58 def redirect(url) Response.redirect(url) end |
#remove ⇒ Object
Remove the component’s element from the DOM (render_self false).
51 52 53 |
# File 'lib/phlex/reactive/reply.rb', line 51 def remove Response.remove(@component) end |
#replace(morph: false) ⇒ Object
Re-render in place. ‘morph: true` morphs the subtree (preserves the focused input + caret) instead of an outerHTML swap — see #morph.
36 37 38 |
# File 'lib/phlex/reactive/reply.rb', line 36 def replace(morph: false) Response.replace(@component, morph:) end |
#streams(*strings) ⇒ Object
Self-targeting again: emit exactly these streams with a TOKEN-ONLY refresh (issue #30) — partial/per-field update, NO full-self replace, so the component’s live inputs survive. The bound component supplies the token.
70 71 72 |
# File 'lib/phlex/reactive/reply.rb', line 70 def streams(*strings) Response.streams(@component, *strings) end |