Module: Weft::DSL::Updates::ClassMethods
- Defined in:
- lib/weft/dsl/updates.rb
Instance Method Summary collapse
-
#push_config ⇒ Object
Push configuration (own or inherited).
-
#pushes(every: nil) ⇒ Object
Declare that this component pushes updates via SSE.
-
#refresh_triggers ⇒ Object
All declared refresh triggers (own + inherited).
-
#refreshes(every: nil, on: nil) ⇒ Object
Declare that this component refreshes automatically.
Instance Method Details
#push_config ⇒ Object
Push configuration (own or inherited). Returns nil if no pushes declared.
49 50 51 52 53 54 55 |
# File 'lib/weft/dsl/updates.rb', line 49 def push_config if instance_variable_defined?(:@push_config) @push_config elsif superclass.respond_to?(:push_config) superclass.push_config end end |
#pushes(every: nil) ⇒ Object
Declare that this component pushes updates via SSE.
pushes every: 5.seconds # server pushes on interval
Generates hx-ext="sse", sse-connect, sse-swap on the wrapper element. The Router auto-generates a streaming endpoint at /component_path/_stream (the suffix is the stream_suffix config knob).
Future: pushes on: "event-name" for event-driven server push (v1.0).
40 41 42 43 44 45 46 |
# File 'lib/weft/dsl/updates.rb', line 40 def pushes(every: nil) @push_config = {} return unless every ms = interval_in_ms(every, :pushes) @push_config[:every] = (ms % 1000).zero? ? ms / 1000 : ms / 1000.0 end |
#refresh_triggers ⇒ Object
All declared refresh triggers (own + inherited).
58 59 60 61 62 63 64 |
# File 'lib/weft/dsl/updates.rb', line 58 def refresh_triggers if superclass.respond_to?(:refresh_triggers) superclass.refresh_triggers | own_refresh_triggers else own_refresh_triggers.dup end end |
#refreshes(every: nil, on: nil) ⇒ Object
Declare that this component refreshes automatically.
refreshes every: 10.seconds # polling
refreshes on: "delivery-completed" # event-driven
refreshes every: 10, on: "updated" # both
Generates hx-get, hx-trigger, hx-swap on the wrapper element. Multiple calls accumulate into a single hx-trigger value. Fractional intervals render in htmx's millisecond syntax.
23 24 25 26 27 28 29 |
# File 'lib/weft/dsl/updates.rb', line 23 def refreshes(every: nil, on: nil) if every ms = interval_in_ms(every, :refreshes) own_refresh_triggers << ((ms % 1000).zero? ? "every #{ms / 1000}s" : "every #{ms}ms") end own_refresh_triggers << "#{on} from:body" if on end |