I'm trying to convert my pre-4.24 code using watchUtils to now use reactiveUtils. I have a tool that lets a user place a point on the map, waits for four address point feature layers to load, waits for them to stop updating, then finds the closest address to the point they created. The code looks like this:
Promise.all([
appConfig.activeView.whenLayerView(greenvilleCountyAddresses),
appConfig.activeView.whenLayerView(andersonCountyAddresses),
appConfig.activeView.whenLayerView(pickensCountyAddresses),
appConfig.activeView.whenLayerView(laurensCountyAddresses),
]).then(([layerView1, layerView2, layerView3, layerView4]) => {
return Promise.all(
[
watchUtils.whenFalseOnce(layerView1, "updating"),
watchUtils.whenFalseOnce(layerView2, "updating"),
watchUtils.whenFalseOnce(layerView3, "updating"),
watchUtils.whenFalseOnce(layerView4, "updating"),
]
);
}).then(([layerView1, layerView2, layerView3, layerView4]) => {
addVehicleIncident_FeatureLayerView_GreenvilleCountyAddresses = layerView1.target;
addVehicleIncident_FeatureLayerView_AndersonCountyAddresses = layerView2.target;
addVehicleIncident_FeatureLayerView_PickensCountyAddresses = layerView3.target;
addVehicleIncident_FeatureLayerView_LaurensCountyAddresses = layerView4.target;
findClosestAddress_addVehicleIncident(addressSelectorBuffer, newAddVehicleIncidentFeature, greenvilleCountyAddresses, andersonCountyAddresses, pickensCountyAddresses, laurensCountyAddresses)
});
According to the docs PromisedWatchHandle is now deprecated so the Promise.all isn't working anymore when I try something like this:
Promise.all([
appConfig.activeView.whenLayerView(greenvilleCountyAddresses),
appConfig.activeView.whenLayerView(andersonCountyAddresses),
appConfig.activeView.whenLayerView(pickensCountyAddresses),
appConfig.activeView.whenLayerView(laurensCountyAddresses),
]).then(([layerView1, layerView2, layerView3, layerView4]) => {
return Promise.all(
[
reactiveUtils.when(() => !layerView1.updating,() => {},{once: true}),
reactiveUtils.when(() => !layerView2.updating,() => {},{once: true}),
reactiveUtils.when(() => !layerView3.updating,() => {},{once: true}),
reactiveUtils.when(() => !layerView4.updating,() => {},{once: true}),
]
);
}).then(([layerView1, layerView2, layerView3, layerView4]) => {
addVehicleIncident_FeatureLayerView_GreenvilleCountyAddresses = layerView1.target;
addVehicleIncident_FeatureLayerView_AndersonCountyAddresses = layerView2.target;
addVehicleIncident_FeatureLayerView_PickensCountyAddresses = layerView3.target;
addVehicleIncident_FeatureLayerView_LaurensCountyAddresses = layerView4.target;
findClosestAddress_addVehicleIncident(addressSelectorBuffer, newAddVehicleIncidentFeature, greenvilleCountyAddresses, andersonCountyAddresses, pickensCountyAddresses, laurensCountyAddresses)
});
I'm not the best with Promises so any help/advice would be greatly appreciated!
GIS Supervisor for Greenville Water