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).
Response.replace(self) # re-render in place (the default, explicit)
Response.replace(self).flash(:error, msg) # surface a validation error
Response.replace(self).also_update("heading", html: @record.name) # + a companion element
Response.remove(self) # drop the element (e.g. moderation queue)
Response.redirect(article_url(@article)) # slug changed -> Turbo.visit the new URL
Response.replace(self).stream(Totals.update(@order)) # multi-stream
Constant Summary collapse
- 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
-
.collection_append(component, name, model) ⇒ 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.
- .collection_prepend(component, name, model) ⇒ Object
- .collection_remove(component, name, model) ⇒ Object
-
.default_flash_html(level, content, dismiss_after = nil) ⇒ Object
The default string-flash wrapper: