Binding
Description
Bind(observable) wires a component to a SettableObservable<T> in both directions: user input flows into the observable, and changes to the observable update the component. The observable is the single source of truth, so several components bound to it stay in sync without further wiring.
Binding works on any component that implements IBindableComponent<T>, including TextBox, TextArea, CheckBox, Toggle, Slider, NumberPicker, Rating, Stepper, Pagination, Carousel, Expander, Pivot, ChoiceGroup, StepsSlider<T>, IconToggle<T>, DateRangePicker, Modal, Panel and Drawer. For a list-shaped component such as TagsInput, bind a SettableObservable<IReadOnlyList<T>>.
Usage
The component is seeded from the observable's Value when Bind is called. Any earlier SetValue, SetText or IsChecked on the component is overwritten.
The binding lives as long as the component and the observable. To release it earlier, pass a SubscriptionScope as the second argument and dispose the scope.
A bound Modal, Panel or Drawer shows while the observable is true. Closing it by the X, Escape or light dismiss sets the observable back to false.
Two components, one observable
Typing in either text box updates the other and the read-out. The buttons set the observable directly, and both text boxes follow.
A bound modal
Signatures
| Method | Description |
|---|---|
Bind<TComponent, T>(this TComponent component, SettableObservable<T> source) |
Two-way binding for an IBindableComponent<T>. Returns the component. |
Bind<TComponent, T>(..., SettableObservable<T> source, SubscriptionScope scope) |
The same, with both subscriptions registered in scope. |
Bind<TComponent, T>(this TComponent component, SettableObservable<IReadOnlyList<T>> source) |
Two-way binding for a list-shaped component. |
Bind<TComponent, T>(..., SettableObservable<IReadOnlyList<T>> source, SubscriptionScope scope) |
The same, with a SubscriptionScope. |
API reference
public static class BindingExtensionsProvides two-way binding between a component implementing IBindableComponent{T} and a SettableObservable{T}.
- Namespace
- Tesserae
Methods
| Name | Description |
|---|---|
| Bind | Wires the component to a single source of truth: user input flows into source, and programmatic changes to source are reflected in the component. The component is seeded from source.Value at call time — any prior SetValue/SetText/IsChecked configuration on the component is overwritten. The binding lives for the lifetime of component and source; use the SubscriptionScope overload if you need to tear it down earlier. |
| Overload | |
|---|---|
| Bind<TComponent, T>(TComponent, SettableObservable<T>) | Wires the component to a single source of truth: user input flows into source, and programmatic changes to source are reflected in the component. The component is seeded from source.Value at call time — any prior SetValue/SetText/IsChecked configuration on the component is overwritten. The binding lives for the lifetime of component and source; use the SubscriptionScope overload if you need to tear it down earlier. |
| Bind<TComponent, T>(TComponent, SettableObservable<T>, SubscriptionScope) | Two-way binding overload that registers both subscriptions with scope; disposing the scope releases the binding. |
| Bind<TComponent, T>(TComponent, SettableObservable<IReadOnlyList<T>>) | List-shaped two-way binding: wires a component implementing IBindableListComponent{T} to a SettableObservable<IReadOnlyList<T>>. User edits flow into source, and programmatic changes to source replace the component's items. The component is seeded from source.Value at call time. |
| Bind<TComponent, T>(TComponent, SettableObservable<IReadOnlyList<T>>, SubscriptionScope) | List-shaped two-way binding overload that registers both subscriptions with scope; disposing the scope releases the binding. |
Bind<TComponent, T>(TComponent, SettableObservable<T>)
public static TComponent Bind<TComponent, T>(this TComponent component, SettableObservable<T> source) where TComponent : IBindableComponent<T>Wires the component to a single source of truth: user input flows into source, and programmatic changes to source are reflected in the component. The component is seeded from source.Value at call time — any prior SetValue/SetText/IsChecked configuration on the component is overwritten. The binding lives for the lifetime of component and source; use the SubscriptionScope overload if you need to tear it down earlier.
Parameters
- component TComponent
- source SettableObservable<T>
Bind<TComponent, T>(TComponent, SettableObservable<T>, SubscriptionScope)
public static TComponent Bind<TComponent, T>(this TComponent component, SettableObservable<T> source, SubscriptionScope scope) where TComponent : IBindableComponent<T>Two-way binding overload that registers both subscriptions with scope; disposing the scope releases the binding.
Parameters
- component TComponent
- source SettableObservable<T>
- scope SubscriptionScope
Bind<TComponent, T>(TComponent, SettableObservable<IReadOnlyList<T>>)
public static TComponent Bind<TComponent, T>(this TComponent component, SettableObservable<IReadOnlyList<T>> source) where TComponent : IBindableListComponent<T>List-shaped two-way binding: wires a component implementing IBindableListComponent{T} to a SettableObservable<IReadOnlyList<T>>. User edits flow into source, and programmatic changes to source replace the component's items. The component is seeded from source.Value at call time.
Parameters
- component TComponent
- source SettableObservable<IReadOnlyList<T>>
Bind<TComponent, T>(TComponent, SettableObservable<IReadOnlyList<T>>, SubscriptionScope)
public static TComponent Bind<TComponent, T>(this TComponent component, SettableObservable<IReadOnlyList<T>> source, SubscriptionScope scope) where TComponent : IBindableListComponent<T>List-shaped two-way binding overload that registers both subscriptions with scope; disposing the scope releases the binding.
Parameters
- component TComponent
- source SettableObservable<IReadOnlyList<T>>
- scope SubscriptionScope
public interface IObservableComponent<T>Defines a component that exposes its value as an observable.
Type Parameters
- T
- The type of the value.
- Namespace
- Tesserae
Methods
| Name | Description |
|---|---|
| AsObservable | Gets an observable that tracks the component's value. |
public interface IObservableListComponent<T>Defines a component that exposes its list of values as an observable.
Type Parameters
- T
- The type of the items in the list.
- Namespace
- Tesserae
Methods
| Name | Description |
|---|---|
| AsObservable | Gets an observable that tracks the component's list of values. |
public interface IBindableComponent<T> : IObservableComponent<T>Defines a component whose value can both be observed and programmatically set, enabling two-way binding against a SettableObservable<T> via the .Bind extension.
Type Parameters
- T
- The type of the value.
- Namespace
- Tesserae
- Implements
- IObservableComponent<T>
Methods
| Name | Description |
|---|---|
| SetBoundValue | Sets the component's value as the result of a binding push from a source observable. Implementations must update the visual/DOM state and the internal observable, but must not raise a user-interaction event that would echo back to the bound source. |
void SetBoundValue(T value)Sets the component's value as the result of a binding push from a source observable. Implementations must update the visual/DOM state and the internal observable, but must not raise a user-interaction event that would echo back to the bound source.
public interface IBindableListComponent<T> : IObservableListComponent<T>Defines a list-shaped component whose value can both be observed and programmatically replaced, enabling two-way binding against a SettableObservable<IReadOnlyList<T>> via the .Bind extension.
Type Parameters
- T
- The type of the items in the list.
- Namespace
- Tesserae
- Implements
- IObservableListComponent<T>
Methods
| Name | Description |
|---|---|
| SetBoundValues | Replaces the component's items as the result of a binding push from a source observable. Implementations must update the visual/DOM state and the internal observable, but must not raise a user-interaction event that would echo back to the bound source. |
void SetBoundValues(IReadOnlyList<T> values)Replaces the component's items as the result of a binding push from a source observable. Implementations must update the visual/DOM state and the internal observable, but must not raise a user-interaction event that would echo back to the bound source.