Class: Phlex::Reactive::Response
- Inherits:
-
Object
- Object
- Phlex::Reactive::Response
- Defined in:
- lib/phlex/reactive/response.rb
Overview
An explicit, immutable description of the ACTOR's HTTP response to a reactive action. An action MAY return one; if it returns anything else (the legacy contract — return value ignored), the endpoint falls back to the implicit single component.to_stream_replace.
A Response governs ONLY the actor's HTTP reply. Cross-tab updates still go through Streamable's broadcast_*_to(..., exclude: reactive_connection_id).
An action builds one through reply (issue #182 — the ONE door; the former
Response.* class verbs are removed and raise a guided rewrite):
reply.replace # re-render in place (the default, explicit)
reply.replace.flash(:error, msg) # surface a validation error
reply.replace.also(heading: @record.name) # + a companion element by id
reply.remove # drop the element (e.g. moderation queue)
reply.redirect(article_url(@article)) # slug changed -> Turbo.visit the new URL
reply.replace.stream(Totals.update(@order)) # multi-stream
Constant Summary collapse
- REMOVED_CLASS_VERBS =
Issue #182:
replyis the ONE documented door. Each former public class verb (Response.replace(self), …) is removed — it raises a guided ArgumentError naming thereply.<verb>rewrite. The builder BODIES live on as internal-usebuild_*class methods (public in Ruby terms — Reply calls them directly — but NOT part of the documented reply-facing surface; Response stays the single place that knows how to construct itself). The rewrite shown for a collection verb points at the keyword form (issue #182). { replace: "reply.replace", morph: "reply.morph", update: "reply.update", remove: "reply.remove", redirect: "reply.redirect(url)", with: "reply.with(*streams)", streams: "reply.streams(*streams)", collection_append: "reply.append(model, to: :name)", collection_prepend: "reply.prepend(model, to: :name)", collection_remove: "reply.remove(model, from: :name)" }.freeze
- NO_SEGMENTS =
render_self: when true (default for replace/update/with), the endpoint GUARANTEES the component's own replace is present so its data-reactive-token-value refreshes (the client extracts the next token from the response HTML). remove/redirect set it false (nothing stays).
token_component: set by .streams (issue #30) — a partial update that opts OUT of the full-self replace but still needs the token refreshed. The endpoint appends this component's tiny to_stream_token instead, so the token rolls forward without re-rendering (and clobbering) the children.
subject_component: the component a self-targeting builder (replace/morph/ update) re-renders (issue #97). Distinct from token_component so it does NOT trip refresh_token? — it exists only to default #js's target to the bound component's id, so reply.morph.js(js.focus("@root")) scopes to the morphed root without the caller repeating the id. No deferred segments — the shared default so the common (non-defer) reply never allocates an empty array per Response.
[].freeze
Instance Attribute Summary collapse
-
#deferred_segments ⇒ Object
readonly
The recorded reply.defer segments (issue #165), in call order.
-
#redirect_url ⇒ Object
readonly
Returns the value of attribute redirect_url.
-
#streams ⇒ Object
readonly
Returns the value of attribute streams.
-
#subject_component ⇒ Object
readonly
Returns the value of attribute subject_component.
-
#token_component ⇒ Object
readonly
Returns the value of attribute token_component.
Class Method Summary collapse
-
.build_collection_append(component, name, model, **row_kwargs) ⇒ Object
--- Reactive collections (issue #35) --- Add/remove a row in a declared reactive_collection, emitting the row stream + the count companion update + the empty-state toggle as ONE Response.
- .build_collection_prepend(component, name, model, **row_kwargs) ⇒ Object
- .build_collection_remove(component, name, model) ⇒ Object
-
.build_morph(component) ⇒ Object
Re-render the component in place via Idiomorph (issue #28).
-
.build_redirect(url) ⇒ Object
Client-side full navigation (Turbo.visit).
-
.build_remove(component) ⇒ Object
Remove the component's element from the DOM.
-
.build_replace(component, morph: false) ⇒ Object
Re-render the component in place (explicit form of today's default).
-
.build_streams(component, *strings) ⇒ Object
Partial / per-field update with a TOKEN-ONLY refresh (issue #30).
-
.build_update(component, morph: false) ⇒ Object
Update only inner HTML (preserves the root element + its token attr).
-
.build_with(*strings) ⇒ Object
Escape hatch / multi-stream root: zero or more raw turbo-stream strings.
-
.default_flash_html(level, content, dismiss_after = nil) ⇒ Object
The default string-flash wrapper: