Watcher
Defined in: watcher.ts:116
Watcher for tracking changes to observable properties
- Automatically tracks
@observableand@computedproperties - Supports
@watchand@watch.refannotations - Can track nested objects
- Provides change detection at both property and path levels
- Can be temporarily disabled via
unwatch()
Static Members
Section titled “Static Members”isWatching
Section titled “isWatching”Get Signature
Section titled “Get Signature”get
staticisWatching():boolean
Defined in: watcher.ts:159
Whether Watcher is enabled in the current transaction
Returns
Section titled “Returns”boolean
staticget<T>(target):Watcher
Defined in: watcher.ts:134
Get a watcher instance for the target object.
Type Parameters
Section titled “Type Parameters”T extends object
Parameters
Section titled “Parameters”target
Section titled “target”T
Returns
Section titled “Returns”Watcher
Remarks
Section titled “Remarks”- Returns existing instance if one exists for the target
- Creates new instance if none exists
- Instances are cached, and garbage collected with the target only if everything they observe is too
Throws
Section titled “Throws”TypeError if the target is not an object.
getSafe()
Section titled “getSafe()”
staticgetSafe(target):Watcher|null
Defined in: watcher.ts:145
Get a watcher instance for the target object.
Same as Watcher.get but returns null instead of throwing an error.
Parameters
Section titled “Parameters”target
Section titled “target”any
Returns
Section titled “Returns”Watcher | null
Members
Section titled “Members”
readonlyid:string
Defined in: watcher.ts:117
changed
Section titled “changed”Get Signature
Section titled “Get Signature”get changed():
boolean
Defined in: watcher.ts:193
Whether changes have been made
Returns
Section titled “Returns”boolean
@computed
changedKeyPaths
Section titled “changedKeyPaths”Get Signature
Section titled “Get Signature”get changedKeyPaths():
ReadonlySet<KeyPath>
Defined in: watcher.ts:216
The key paths that have changed
Keys of nested objects are included.
Returns
Section titled “Returns”ReadonlySet<KeyPath>
@computed
changedKeys
Section titled “changedKeys”Get Signature
Section titled “Get Signature”get changedKeys():
ReadonlySet<KeyPath>
Defined in: watcher.ts:206
The keys that have changed
Remarks
Section titled “Remarks”- Does not include keys of nested objects
- Cleared when reset() is called
- Updated when properties are modified
Returns
Section titled “Returns”ReadonlySet<KeyPath>
@computed
changedTick
Section titled “changedTick”Get Signature
Section titled “Get Signature”get changedTick():
bigint
Defined in: watcher.ts:187
The total number of changes processed
Observe this value to react to changes.
Remarks
Section titled “Remarks”- Incremented for each change and each affected key
- Not affected by assumeChanged()
- Reset to 0 when reset() is called
Returns
Section titled “Returns”bigint
nested
Section titled “nested”Get Signature
Section titled “Get Signature”get nested():
ReadonlyMap<KeyPath,Watcher>
Defined in: watcher.ts:227
Nested watchers
Returns
Section titled “Returns”ReadonlyMap<KeyPath, Watcher>
assumeChanged()
Section titled “assumeChanged()”assumeChanged():
void
Defined in: watcher.ts:257
@action
Assume some changes have been made
It only changes changed to true and does not increment changedTick.
Returns
Section titled “Returns”void
reset()
Section titled “reset()”reset():
void
Defined in: watcher.ts:241
@action
Reset the changed state
Returns
Section titled “Returns”void
Remarks
Section titled “Remarks”- Clears all changed keys
- Resets changedTick to 0
- Clears assumeChanged flag
- Resets all nested watchers