Module: Phlex::Reactive
- Defined in:
- lib/phlex/reactive.rb,
lib/phlex/reactive/engine.rb,
lib/phlex/reactive/version.rb,
lib/phlex/reactive/component.rb,
lib/phlex/reactive/streamable.rb,
app/controllers/phlex/reactive/actions_controller.rb
Overview
phlex-reactive: reactive Phlex components for Rails.
Two cooperating mixins, one client runtime, one endpoint:
* Phlex::Reactive::Streamable — gives a component a stable `id` and class
methods to render itself as a Turbo Stream (`.replace`, `.append`, ...)
and to broadcast itself (`.broadcast_replace_to`, ...). The server->client
half (controller responses + background broadcasts).
* Phlex::Reactive::Component — declares client-invokable `action`s and
emits a signed identity token + the wiring the generic `reactive`
Stimulus controller needs. The client->server half (clicks, form input).
Both halves converge on ONE re-render unit: the component, targeted by its ‘id`. See the README for the mental model and examples.
Defined Under Namespace
Modules: Component, Streamable Classes: ActionsController, Engine, Error, InvalidToken
Constant Summary collapse
- IDENTITY_PURPOSE =
Purpose string bound into every identity token’s signature so a token minted for phlex-reactive can’t be replayed against another verifier use.
"phlex-reactive/identity"- VERSION =
"0.1.0"
Class Attribute Summary collapse
- .action_path ⇒ Object
-
.authorization_errors ⇒ Object
Exception classes the action endpoint renders as 403.
- .base_controller_name ⇒ Object
- .renderer ⇒ Object
- .verifier ⇒ Object
Class Method Summary collapse
- .base_controller ⇒ Object
-
.sign(payload) ⇒ Object
Signs a payload hash into an identity token.
-
.verify(token) ⇒ Object
Returns the verified payload hash, or nil if the token is invalid.
Class Attribute Details
.action_path ⇒ Object
63 64 65 |
# File 'lib/phlex/reactive.rb', line 63 def action_path @action_path ||= "/reactive/actions" end |
.authorization_errors ⇒ Object
Exception classes the action endpoint renders as 403. Append your authorization library’s error (Pundit::NotAuthorizedError, ActionPolicy::Unauthorized, …).
55 56 57 |
# File 'lib/phlex/reactive.rb', line 55 def @authorization_errors end |
.base_controller_name ⇒ Object
75 76 77 |
# File 'lib/phlex/reactive.rb', line 75 def base_controller_name @base_controller_name ||= "ActionController::Base" end |
.renderer ⇒ Object
71 72 73 |
# File 'lib/phlex/reactive.rb', line 71 def renderer @renderer ||= defined?(::ActionController::Base) ? ::ActionController::Base : nil end |
.verifier ⇒ Object
67 68 69 |
# File 'lib/phlex/reactive.rb', line 67 def verifier @verifier ||= default_verifier end |
Class Method Details
.base_controller ⇒ Object
79 80 81 |
# File 'lib/phlex/reactive.rb', line 79 def base_controller base_controller_name.constantize end |
.sign(payload) ⇒ Object
Signs a payload hash into an identity token.
89 90 91 |
# File 'lib/phlex/reactive.rb', line 89 def sign(payload) verifier.generate(payload, purpose: IDENTITY_PURPOSE) end |
.verify(token) ⇒ Object
Returns the verified payload hash, or nil if the token is invalid.
84 85 86 |
# File 'lib/phlex/reactive.rb', line 84 def verify(token) verifier.verified(token, purpose: IDENTITY_PURPOSE) end |