unwatch
Annotation for unwatching changes to a property and a getter
When used as an annotation:
- Combine with
@observableor@nested(and their variants) to stop watching changes.
@computedneeds none, as it is not watched unless@watchis specified. - You cannot re-enable watching once
@unwatchis specified.
When used as a function:
- Runs a piece of code without changes being detected by Watcher.
unwatch(() => (model.field = "value"));
- Only what the function itself changes goes undetected. Watching resumes as soon as it returns, so the changes
made around it are detected as usual, even when all of it happens in one transaction.runInAction(() => {model.field1 = "value"; // Detectedunwatch(() => {model.field2 = "value"; // Not detected});model.field3 = "value"; // Detected}); - Limitation: a watcher processes changes in batches, where all it can tell is when a key first changed in the
batch. A key that the function changes therefore goes undetected until the next batch — the rest of the
transaction, or longer under a customreactionScheduler. A key changed before the function and again inside
it is detected.
Call Signature
Section titled “Call Signature”unwatch(
action):void
Defined in: watcher.ts:181
Parameters
Section titled “Parameters”action
Section titled “action”() => void
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”unwatch(
target,propertyKey):void
Defined in: watcher.ts:181
Parameters
Section titled “Parameters”target
Section titled “target”object
propertyKey
Section titled “propertyKey”string | symbol
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”unwatch(
value,context):void| ((this:object) =>any)
Defined in: watcher.ts:181
Parameters
Section titled “Parameters”(this: object) => any
context
Section titled “context”ClassGetterDecoratorContext
Returns
Section titled “Returns”void | ((this: object) => any)
Call Signature
Section titled “Call Signature”unwatch(
value,context):void|ClassAccessorDecoratorResult<object,any>
Defined in: watcher.ts:181
Parameters
Section titled “Parameters”ClassAccessorDecoratorTarget<object, any>
context
Section titled “context”ClassAccessorDecoratorContext
Returns
Section titled “Returns”void | ClassAccessorDecoratorResult<object, any>
Call Signature
Section titled “Call Signature”unwatch(
value,context):any
Defined in: watcher.ts:181
Parameters
Section titled “Parameters”undefined
context
Section titled “context”ClassFieldDecoratorContext<object, any>
Returns
Section titled “Returns”any