If true, then the callback of changing is also fired on mutations of nested properties
When providing the specific path to watch, this parameter can contain a list of dependencies for the watching path. This parameter can help to watch accessors.
const obj = {
get foo() {
return this.bla * this.baz;
},
bla: 2,
baz: 3
};
const {proxy} = watch(obj, 'foo', {dependencies: ['bla', 'baz']}, (value, oldValue, info) => {
console.log(value, oldValue, info.path, info.originalPath, info.parent);
});
// This mutation will invoke our callback
proxy.bla++;
When providing the specific path to watch, this parameter can contain an object or Map
with lists of
dependencies to watch.
const obj = {
foo: {
get value() {
return this.bla * this.baz;
}
},
bla: 2,
baz: 3
};
const depsAsObj = {
'foo.value': ['bla', 'baz']
};
const {proxy: proxy1} = watch(obj, {dependencies: depsAsObj}, (mutations) => {
mutations.forEach(([value, oldValue, info]) => {
console.log(value, oldValue, info.path, info.originalPath, info.parent);
});
});
// This mutation will fire an additional event for `foo.value`
proxy1.bla++;
const depsAsMap = new Map([
[
// A path to the property with dependencies
['foo', 'value'],
// Dependencies
['bla', 'baz']
]
]);
const {proxy: proxy2} = watch(obj, {dependencies: depsAsMap}, (mutations) => {
mutations.forEach(([value, oldValue, info]) => {
console.log(value, oldValue, info.path, info.originalPath, info.parent);
});
});
proxy2.baz++;
Watch engine to use. By default, will be used proxy if supported, otherwise accessors.
A filter function for mutation events. The function allows skipping some mutation events.
If true, then all mutation events will be fired immediately. Notice, with enabling this option, the callback changes its interface:
// Before
type Cb = (mutations: [[unknown, unknown, WatchHandlerParams]]) => any;
// After
type CbWithImmediate = (newValue: unknown, oldValue: unknown, info: WatchHandlerParams) => any;
A function that takes a path of the mutation event and returns a new path. The function is used when you want to mask one mutation to another one.
List of postfixes for paths to watch. This parameter can help to watch accessors.
List of prefixes for paths to watch. This parameter can help to watch accessors.
Link to an object that should connect with the watched object, i.e., changing of properties of the tied object, will also emit mutation events
If true, then the callback of changing is also fired on mutations of properties from prototypes
The option enables or disables collapsing of mutation events. When it toggles to
true
, all mutation events fire as if they occur on top properties of the watchable object.When it toggles to
false,
and the watcher binds to the specified path, the callback takes a list of mutations. Otherwise, the callback takes only the last mutation.false