It's great that onDidChange
and onDidAnyChange
return functions to destroy the watcher, but it would be great to have the listeners be internal state and then provide an unsubscribe
method. This is especially nicer when you need to manage multiple Conf instances at once.
Before
let conf1 = undefined
let unsubscribeConf1 = undefined
let conf2 = undefined
let unsubscribeConf2 = undefined
export foo = () => {
if (unsubscribeConf1) unsubscribeConf1()
conf1 = new Conf(...)
unsubscribeConf1 = conf1.onDidAnyChange(...)
}
export bar = () => {
if (unsubscribeConf2) unsubscribeConf2()
conf2 = new Conf(...)
unsubscribeConf2 = conf2.onDidAnyChange(...)
}
After
let conf1 = undefined
let conf2 = undefined
export foo = () => {
if (conf1) conf1.unsubscribe()
conf1 = new Conf(...)
conf1.onDidAnyChange(...)
}
export bar = () => {
if (conf2) conf2.unsubscribe()
conf2 = new Conf(...)
conf2.onDidAnyChange(...)
}
Another, more sophisticated, approach, might be providing pause()
, stop()
, start()
methods allowing for more granular control over watching
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too