Basic Usage
Thelinked() function creates a computed observable with both get and set capabilities:
Type Signature
Shorthand Syntax
You can pass theget function as the first parameter:
Synchronizing Multiple Observables
Linked observables are perfect for synchronizing state across multiple observables:Nested Property Access
You can set child properties of linked observables:Setting Before Activation
Linked observables can be set before they’re activated (before theget function runs):
Batched Updates
When setting multiple properties, the setter receives the batched changes:Async Getters
Linked observables support async getters for loading remote data:Activation Modes
Control when the linked observable activates:Initial Value
Provide an initial value before the getter runs:Wait Conditions
Delay activation until certain conditions are met:Use Cases
Form Field Transformations
State Derivation
Type Conversion
Best Practices
- Keep getters pure: Getter functions should not have side effects
- Handle edge cases: Account for undefined or null values in transformations
- Use batching: When setting multiple related values, use
batch()for better performance - Avoid circular dependencies: Be careful not to create infinite loops between linked observables
- Consider async carefully: Use async getters only when necessary, as they add complexity
Related
- Computed Observables - Read-only computed values
- when() - Wait for conditions
- observe() - React to changes