Class: Weft::Context

Inherits:
Arbre::Context
  • Object
show all
Includes:
Expansion, Interception, Modifiers, Wiring
Defined in:
lib/weft/context.rb,
lib/weft/context/wiring.rb,
lib/weft/context/expansion.rb,
lib/weft/context/modifiers.rb,
lib/weft/context/traversal.rb,
lib/weft/context/interception.rb

Overview

Arbre::Context subclass that intercepts element creation to expand Weft kwargs into htmx attributes — the kwarg vocabulary and its claim rules live in Context::Expansion.

Works at every nesting depth because Arbre instance_evals the top-level block, making the Context the receiver for all insert_tag calls throughout the element tree.

Defined Under Namespace

Modules: Expansion, Interception, Modifiers, Traversal, Wiring

Constant Summary collapse

SLOT_TAKEN =

Thrown with the contested DOM id when a root loses a slot. Caught by whoever asked for the render; nothing partial reaches the tree, because Arbre adds a tag to its parent only after the build returns.

:weft_slot_taken

Constants included from Modifiers

Modifiers::CLAIMING_MODIFIER_KEYS, Modifiers::MODIFIER_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Modifiers

warned_standalone_swaps

Methods included from Interception

#insert_tag

Methods included from Expansion

#expand_weft_attrs, #weft_kwarg?

Constructor Details

#initialize(assigns = {}, helpers = nil, wire_params: nil, overlays: nil, branch_bag: nil, slots: nil) ⇒ Context

Two positional parameters are Arbre's own signature; the four keywords are Weft's render-scoped channels, each independently optional. That they have grown to four is a fair signal that they want a render-environment object of their own — a change that would touch every render path and a documented constructor, so it belongs with the lifecycle work, not here.



62
63
64
65
66
67
68
69
# File 'lib/weft/context.rb', line 62

def initialize(assigns = {}, helpers = nil, wire_params: nil, overlays: nil, # rubocop:disable Metrics/ParameterLists
               branch_bag: nil, slots: nil, &)
  @wire_params = wire_params || {}
  @overlays = overlays || {}
  @branch_bag = branch_bag
  @slots = slots
  super(assigns, helpers, &)
end

Instance Attribute Details

#branch_bagObject (readonly)

A bag for ROOT components to branch from, standing in for the tree ancestor a root doesn't have — how an OOB companion inherits its primary's bag (rich values included) exactly like a child built in the primary's own build.



41
42
43
# File 'lib/weft/context.rb', line 41

def branch_bag
  @branch_bag
end

#overlaysObject (readonly)

Request-scoped overlay values — the accumulated verb-block deltas (action callable returns, includes deltas, recovery injections). In the source stack an overlay entry speaks AS the wire for its key: a value overrides the wire's, a nil clears it (resolution falls below). One universe per request; these are its amendments.



35
36
37
# File 'lib/weft/context.rb', line 35

def overlays
  @overlays
end

#slotsObject (readonly)

The DOM ids this RESPONSE has already spoken for — a Set shared across every context the response builds in, because the primary and each of its companions get their own. An out-of-band swap is addressed by DOM id, so only one fragment per id can land; a root component claims its id as it builds (Component#claim_dom_slot!) and a second claimant abandons its render by throwing SLOT_TAKEN. Absent on renders with nothing to arbitrate, and nothing is claimed then.



50
51
52
# File 'lib/weft/context.rb', line 50

def slots
  @slots
end

#wire_paramsObject (readonly)

The render's wire params (query/body/path values), carried on the context so every component in the tree resolves its own declared params at any depth. Assigned before super because Arbre's initialize instance_evals the construction block — the tree builds during super.



28
29
30
# File 'lib/weft/context.rb', line 28

def wire_params
  @wire_params
end

Instance Method Details

#stage_received(klass, values) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

One-shot register for receives hand-offs. Interception stages the extracted kwargs here immediately before Arbre constructs the target (insert_tag → build_tag → new); the new instance consumes them during params assembly. Class-checked so a stale staging can never leak into a different component's bag.



77
78
79
# File 'lib/weft/context.rb', line 77

def stage_received(klass, values)
  @staged_received = [klass, values]
end

#take_received!(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



82
83
84
85
86
87
88
# File 'lib/weft/context.rb', line 82

def take_received!(klass)
  staged_class, values = @staged_received
  return unless staged_class.equal?(klass)

  @staged_received = nil
  values
end