Class: Sinatra::Inertia::Prop
- Inherits:
-
Object
- Object
- Sinatra::Inertia::Prop
- Defined in:
- lib/sinatra/inertia/deferred.rb
Overview
Wrappers that mark props with Inertia v2 transport modes. They are plain value objects with a Proc payload; resolution happens inside PropsResolver (which knows whether the current request is a partial reload, what component it targets, what fields are requested, etc.).
Usage:
inertia 'Page', props: {
todos: -> { Todo.all }, # plain lazy: included by default, resolved on demand
stats: Inertia.defer { compute_stats } # excluded from initial response, fetched in 2nd request
csrf: Inertia.always { csrf_token } # included even on partial reloads that omit it
filter: Inertia.optional { params[:f] } # only included when explicitly requested via partial
feed: Inertia.merge(page_items) # array merged with existing client-side feed
once: Inertia.once { current_time } # delivered exactly once; subsequent visits suppress
}
Direct Known Subclasses
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#always? ⇒ Boolean
Should this prop be included in every response (including partials that did not request it)?.
-
#deferred? ⇒ Boolean
Is the value sent in the initial response, or deferred to a second roundtrip?.
-
#initialize(block: nil, value: nil, group: 'default') ⇒ Prop
constructor
A new instance of Prop.
-
#merge? ⇒ Boolean
Should arrays returned by this prop be merged with the client’s existing array (Inertia 2 merge semantics)?.
-
#once? ⇒ Boolean
Once-only delivery (cleared from session/state after first emission).
-
#optional? ⇒ Boolean
Is this prop only included when explicitly requested via X-Inertia-Partial-Data?.
- #resolve ⇒ Object
Constructor Details
#initialize(block: nil, value: nil, group: 'default') ⇒ Prop
Returns a new instance of Prop.
22 23 24 25 26 |
# File 'lib/sinatra/inertia/deferred.rb', line 22 def initialize(block: nil, value: nil, group: 'default') @block = block @value = value @group = group end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
20 21 22 |
# File 'lib/sinatra/inertia/deferred.rb', line 20 def block @block end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
20 21 22 |
# File 'lib/sinatra/inertia/deferred.rb', line 20 def group @group end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
20 21 22 |
# File 'lib/sinatra/inertia/deferred.rb', line 20 def value @value end |
Instance Method Details
#always? ⇒ Boolean
Should this prop be included in every response (including partials that did not request it)?
34 |
# File 'lib/sinatra/inertia/deferred.rb', line 34 def always? = false |
#deferred? ⇒ Boolean
Is the value sent in the initial response, or deferred to a second roundtrip?
38 |
# File 'lib/sinatra/inertia/deferred.rb', line 38 def deferred? = false |
#merge? ⇒ Boolean
Should arrays returned by this prop be merged with the client’s existing array (Inertia 2 merge semantics)?
46 |
# File 'lib/sinatra/inertia/deferred.rb', line 46 def merge? = false |
#once? ⇒ Boolean
Once-only delivery (cleared from session/state after first emission).
49 |
# File 'lib/sinatra/inertia/deferred.rb', line 49 def once? = false |
#optional? ⇒ Boolean
Is this prop only included when explicitly requested via X-Inertia-Partial-Data?
42 |
# File 'lib/sinatra/inertia/deferred.rb', line 42 def optional? = false |
#resolve ⇒ Object
28 29 30 |
# File 'lib/sinatra/inertia/deferred.rb', line 28 def resolve block ? block.call : value end |