KeyedObservableStack
Description
KeyedObservableStack renders an ObservableList<IComponentWithID> as a stack and, on each change, reconciles the DOM instead of rebuilding it. Rows are matched by their Identifier; a matched row is re-rendered only when its ContentHash changes, surviving rows are moved into the new order, dropped rows are removed and new ones inserted. Any reorder moves the existing elements, so scroll position, focus and DOM state in untouched rows are kept. Changes are debounced unless the stack is constructed with debounce: false.
Usage
There is no UI. factory: construct it with new KeyedObservableStack(items) and drive it by mutating the list. Each item implements IComponentWithID, returning a stable Identifier and a ContentHash that changes exactly when the rendered content would.
API reference
public class KeyedObservableStack : IComponent, IHasBackgroundColor, IHasMarginPadding, ISpecialCaseStyling, ICanWrapA Stack whose children are driven by an ObservableList{T} of IComponentWithID. On every change it performs a keyed reconcile against the live DOM rather than rebuilding: existing children are matched by their string Identifier, a matched child is re-rendered (replaceChild) only when its ContentHash changes, surviving children are reordered to match the new sequence, dropped items are removed and new items inserted. Changes are debounced by default.
Remarks
Use this when your items are (or can cheaply be) rendered components that each expose a stable key and a content hash, and you want reordering and/or content-hash-driven replacement (e.g. a server-driven or streaming list such as Chat). For the complementary case, see ObservableStack{T}: it keys data models by reference identity, builds each row lazily via a factory, and never replaces a matched row (rows refresh their own content via observation). Prefer that when items are data objects identified by reference and each row is a self-managing component you do not want rebuilt. Note that it only diffs a common prefix/suffix, so a reorder of interior rows rebuilds that span, whereas KeyedObservableStack handles arbitrary reorders.
- Namespace
- Tesserae
- Implements
- IComponent, IHasBackgroundColor, IHasMarginPadding, ISpecialCaseStyling, ICanWrap
Constructors
| Name | Description |
|---|---|
| KeyedObservableStack | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| StackOrientation | Gets or sets the stack orientation. |
| CanWrap | Gets or sets a value indicating whether the component's text can wrap onto multiple lines. |
| IsInline | Returns a value indicating whether the component is inline. |
| InnerElement | Gets the underlying DOM element backing this component. |
| Background | Gets or sets the CSS background of the component. |
| Margin | Gets or sets the CSS margin of the component. |
| Padding | Gets or sets the CSS padding of the component. |
| StylingContainer | Gets or sets the styling container. |
| PropagateStylesToWrapper | Gets whether a sizing helper applied to this component should tag it so a wrapper-building container hoists the style onto the wrapper. |
public Orientation StackOrientation { get ; set ; }Gets or sets the stack orientation.
public bool CanWrap { get ; set ; }Gets or sets a value indicating whether the component's text can wrap onto multiple lines.
public bool IsInline { get ; set ; }Returns a value indicating whether the component is inline.
public HTMLElement InnerElement { get; private set; }Gets the underlying DOM element backing this component.
public string Background { get ; set ; }Gets or sets the CSS background of the component.
public string Margin { get ; set ; }Gets or sets the CSS margin of the component.
public string Padding { get ; set ; }Gets or sets the CSS padding of the component.
public HTMLElement StylingContainerGets or sets the styling container.
Methods
| Name | Description |
|---|---|
| AlignItems | Sets the align-items css property for this stack |
| AlignItemsCenter | Sets the align-items css property for this stack to 'center' |
| Relative | Make this stack relative (i.e. position:relative) |
| AlignContent | Sets the align-content CSS property for this stack. |
| JustifyContent | Sets the justify-content CSS property for this stack. |
| JustifyItems | Sets the justify-items CSS property for this stack. |
| RemovePropagation | Removes the given propagation from the component. |
| OnMouseOver | Registers a callback invoked when the mouse over event fires. |
| OnMouseOut | Registers a callback invoked when the mouse out event fires. |
| Clear | Clears the component's current state. |
| Render | Renders the component's root HTML element. |
| Horizontal | Configures the component to horizontal. |
| Vertical | Configures the component to vertical. |
| HorizontalReverse | Configures the horizontal reverse on the component. |
| VerticalReverse | Configures the vertical reverse on the component. |
| Wrap | Allows the component's content to wrap onto multiple lines. |
| Inline | Renders the component inline. |
| NoWrap | Removes / disables the wrap on the component. |
| OverflowHidden | Hides any content that overflows the component's bounds. |
| NoDefaultMargin | Removes / disables the default margin on the component. |
| Skeleton | Configures the component to skeleton. |
public KeyedObservableStack AlignItems(ItemAlign align)Sets the align-items css property for this stack
Parameters
- align
public KeyedObservableStack AlignItemsCenter()Sets the align-items css property for this stack to 'center'
Parameters
- align
public KeyedObservableStack Relative()Make this stack relative (i.e. position:relative)
public KeyedObservableStack AlignContent(ItemAlign align)Sets the align-content CSS property for this stack.
Parameters
- align
- The alignment.
Returns
The current instance.
public KeyedObservableStack JustifyContent(ItemJustify justify)Sets the justify-content CSS property for this stack.
Parameters
- justify
- The justification.
Returns
The current instance.
public KeyedObservableStack JustifyItems(ItemJustify justify)Sets the justify-items CSS property for this stack.
Parameters
- justify
- The justification.
Returns
The current instance.
public KeyedObservableStack RemovePropagation()Removes the given propagation from the component.
public KeyedObservableStack OnMouseOver(ComponentEventHandler<KeyedObservableStack, Event> onMouseOver)Registers a callback invoked when the mouse over event fires.
public KeyedObservableStack OnMouseOut(ComponentEventHandler<KeyedObservableStack, Event> onMouseOut)Registers a callback invoked when the mouse out event fires.
public virtual HTMLElement Render()Renders the component's root HTML element.
public KeyedObservableStack Horizontal()Configures the component to horizontal.
public KeyedObservableStack Vertical()Configures the component to vertical.
public KeyedObservableStack HorizontalReverse()Configures the horizontal reverse on the component.
public KeyedObservableStack VerticalReverse()Configures the vertical reverse on the component.
public KeyedObservableStack Wrap()Allows the component's content to wrap onto multiple lines.
public KeyedObservableStack NoWrap()Removes / disables the wrap on the component.
public KeyedObservableStack OverflowHidden()Hides any content that overflows the component's bounds.
public KeyedObservableStack NoDefaultMargin()Removes / disables the default margin on the component.
public interface IComponentWithID : IComponent- Namespace
- Tesserae
- Implements
- IComponent