I'm trying to persist the settings as a User changes things like SnappingOptions:

Here's the gist of how I've attempted to do this:
const optionsObject = new SnappingOptions(initialSettings);
const listenForFeatureEnabled = optionsObject.watch('featureEnabled', () => {
persistSnappingSettings(optionsObject);
});
const listenForSelfEnabled = optionsObject.watch('selfEnabled', () => {
persistSnappingSettings(optionsObject);
});
// ... more code ...
optionsObject.addHandles([
listenForFeatureEnabled,
listenForSelfEnabled,
// ... more listeners ...
])
Things start to get ugly with the FeatureSnappingLayerSource objects.
const listenForFeatureSourceChanges = optionsObject.featureSources.on('change', (event) => {
// This is helpful when a new layer is added to the MapView
persistSnappingSettings(optionsObject);
// @ts-ignore
event.target.forEach((fs: FeatureSnappingLayerSource) => {
if (!fs.get(isBeingTrackedIndicator)) {
fs.set(isBeingTrackedIndicator, true);
reactiveUtils.watch(() => fs.enabled, () => {
persistSnappingSettings(optionsObject);
});
}
});
});
I have a 3 part question:
- Is there an easier way to watch these properties, or is this the "Esri way"?
- Could ignoring the handles returned on line 9 cause issues? Should I be doing an adding those handles to the optionsObject?
- How can I write unit tests for this? I can verify the optionsObject hasHandles(), but that's not too useful. Can I get ahold of those handles somehow and execute them, or is there some other approach that would let me test that functionality?