Data Binding
Connect DOM elements to data sources and they update automatically when values change.HTML Attribute Binding
Adddata-sbc-bind to any element. The SDK scans for these on load and updates textContent whenever the bound value changes:
JavaScript Binding
Auto-Scan
The SDK automatically scans the DOM on load. If you add elements dynamically, trigger a re-scan:Binding Expressions
Paths resolve against these data sources:| Prefix | Source | Updates on |
|---|---|---|
session.* | Session state (follower count, etc.) | session:update |
goals.* | Goal progress | goal:update |
fields.* | Widget custom field values | widget:field_change |
vars.* | Runtime variables | vars.set() calls |
Cleanup
Remove all bindings under a root element:Example: Live Stats Display
Example: Dynamic Binding with Vars
API Reference
| Method | Description |
|---|---|
SBCanvas.bind.bind(el, expression) | Bind an element to a data expression |
SBCanvas.bind.unbindAll(root?) | Remove bindings under root (or all if omitted) |
SBCanvas.bind.scan(root?) | Scan for data-sbc-bind attributes under root |