Module: InertiaJb::Helper
- Defined in:
- lib/inertia_jb/helper.rb
Overview
Optional syntax sugar available inside .html.inertia templates, so you can
write optional { ... } instead of InertiaRails.optional { ... }.
These delegate to the InertiaRails factory methods; the returned prop
objects are resolved by InertiaRails::PropsResolver when the page is built
(respecting partial reloads, grouping, etc.).
Every block is bound to the current view with bind_to_view so that a lazy prop's block runs in the same context an eager prop would — see that method for why this matters.
Instance Method Summary collapse
-
#always(&block) ⇒ Object
Always fetched, even when not requested in a partial reload.
-
#cache(*args, **kwargs, &block) ⇒ Object
Server-side cached via Rails.cache; the block's result is stored as JSON and reused on subsequent requests until the cache expires.
-
#deep_merge(*args, **kwargs, &block) ⇒ Object
Deep-merged with existing client-side data.
-
#defer(*args, **kwargs, &block) ⇒ Object
Excluded from the initial load; fetched in a follow-up request.
-
#merge(*args, **kwargs, &block) ⇒ Object
Merged with existing client-side data instead of replacing it.
-
#once(*args, **kwargs, &block) ⇒ Object
Sent once and cached client-side; skipped on later visits unless reset or expired.
-
#optional(&block) ⇒ Object
Only fetched when explicitly requested in a partial reload.
-
#scroll(*args, **kwargs, &block) ⇒ Object
Infinite-scroll prop (accepts a paginator or explicit metadata).
Instance Method Details
#always(&block) ⇒ Object
Always fetched, even when not requested in a partial reload.
21 22 23 |
# File 'lib/inertia_jb/helper.rb', line 21 def always(&block) ::InertiaRails.always(&InertiaJb.bind_to_view(self, block)) end |
#cache(*args, **kwargs, &block) ⇒ Object
Server-side cached via Rails.cache; the block's result is stored as JSON and reused on subsequent requests until the cache expires.
52 53 54 |
# File 'lib/inertia_jb/helper.rb', line 52 def cache(*args, **kwargs, &block) ::InertiaRails.cache(*args, **kwargs, &InertiaJb.bind_to_view(self, block)) end |
#deep_merge(*args, **kwargs, &block) ⇒ Object
Deep-merged with existing client-side data.
41 42 43 |
# File 'lib/inertia_jb/helper.rb', line 41 def deep_merge(*args, **kwargs, &block) ::InertiaRails.deep_merge(*args, **kwargs, &InertiaJb.bind_to_view(self, block)) end |
#defer(*args, **kwargs, &block) ⇒ Object
Excluded from the initial load; fetched in a follow-up request.
26 27 28 |
# File 'lib/inertia_jb/helper.rb', line 26 def defer(*args, **kwargs, &block) ::InertiaRails.defer(*args, **kwargs, &InertiaJb.bind_to_view(self, block)) end |
#merge(*args, **kwargs, &block) ⇒ Object
Merged with existing client-side data instead of replacing it.
36 37 38 |
# File 'lib/inertia_jb/helper.rb', line 36 def merge(*args, **kwargs, &block) ::InertiaRails.merge(*args, **kwargs, &InertiaJb.bind_to_view(self, block)) end |
#once(*args, **kwargs, &block) ⇒ Object
Sent once and cached client-side; skipped on later visits unless reset or expired.
46 47 48 |
# File 'lib/inertia_jb/helper.rb', line 46 def once(*args, **kwargs, &block) ::InertiaRails.once(*args, **kwargs, &InertiaJb.bind_to_view(self, block)) end |
#optional(&block) ⇒ Object
Only fetched when explicitly requested in a partial reload.
16 17 18 |
# File 'lib/inertia_jb/helper.rb', line 16 def optional(&block) ::InertiaRails.optional(&InertiaJb.bind_to_view(self, block)) end |
#scroll(*args, **kwargs, &block) ⇒ Object
Infinite-scroll prop (accepts a paginator or explicit metadata).
31 32 33 |
# File 'lib/inertia_jb/helper.rb', line 31 def scroll(*args, **kwargs, &block) ::InertiaRails.scroll(*args, **kwargs, &InertiaJb.bind_to_view(self, block)) end |