front.data_binding#

Data-binding primitives that connect front element values to a backing state store.

A BoundData wraps a keyed slot in a State so an element can read and write its current value through a single object. The ValueNotSet / Empty sentinels distinguish “no value yet” from a deliberate empty value.

Classes

Binder(front_state)

Expose keys of front_state as attributes (or items) that are BoundData handles.

BoundData(id, state)

A read/write handle on one key (id) of a state mapping.

class front.data_binding.Binder(front_state)[source]#

Bases: object

Expose keys of front_state as attributes (or items) that are BoundData handles.

Reading an unknown attribute creates a handle for that key (without writing to the state); assigning to it creates the handle and writes the value.

>>> state = {}
>>> b = Binder(state)
>>> b.foo.get()
ValueNotSet
>>> b.foo = 42
>>> b.foo(), state
(42, {'foo': 42})
>>> b['bar'] = 'hi'
>>> state
{'foo': 42, 'bar': 'hi'}

See also

front.state.mk_binder: a descriptor-based variant with an allow-list of names.

bound_data_factory#

alias of BoundData

class front.data_binding.BoundData(id, state)[source]#

Bases: object

A read/write handle on one key (id) of a state mapping.

get returns ValueNotSet while the key is absent; set writes through to the state. Calling the instance is the same as get.

>>> state = {}
>>> bound = BoundData('x', state)
>>> bound.get()
ValueNotSet
>>> bound.set(3)
>>> bound(), state
(3, {'x': 3})

See also

Binder: makes BoundData handles on demand, as attributes.

get()[source]#

Return the value stored under id, or ValueNotSet.

set(value)[source]#

Write value under id in the state.