Select to view content in your preferred language

How to replace watchUtils.whenFalseOnce to the equivalent in reactiveUtils

675
2
Jump to solution
01-11-2023 03:14 AM
MarceloRosensaft
New Contributor III

Hello,

We have a code chunk that works - taken from a post by @RobErt Scheitlin, but uses watchUtils which is deprecated.

 

watchUtils.whenFalse(view, 'stationary', (evt) => {
        if (!view.stationary) {
            watchUtils.whenTrueOnce(view, 'stationary', function (evt) {
                console.log(view.extent);
            });
        } else {
            watchUtils.whenFalseOnce(view, 'interacting', function (evt) {
                console.log(view.extent);
            });
        }
    })

 

How should we convert it to using the reactiveUtils tools?

Thank you in advance,

Marcelo

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor II

The reactiveUtils have an option object you can provide where you can set "once" to true.

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html#ReactiveL...

Your above code snippet would look something like this, but the way you have it written, the else is unreachable, maybe the main is watch and not whenFalse? 

 

 

	when(
		() => !view.stationary,
		() => {
			console.log("view stationary is: ", view.stationary);
			when(
				() => view.stationary,
				() => console.log("view is now stationary"),
				{ once: true }
			);
		}
	);

 

 

Here is a codepen with both options.

https://codepen.io/odoe/pen/zYLwKGb?editors=0010 

View solution in original post

2 Replies
ReneRubalcava
Frequent Contributor II

The reactiveUtils have an option object you can provide where you can set "once" to true.

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html#ReactiveL...

Your above code snippet would look something like this, but the way you have it written, the else is unreachable, maybe the main is watch and not whenFalse? 

 

 

	when(
		() => !view.stationary,
		() => {
			console.log("view stationary is: ", view.stationary);
			when(
				() => view.stationary,
				() => console.log("view is now stationary"),
				{ once: true }
			);
		}
	);

 

 

Here is a codepen with both options.

https://codepen.io/odoe/pen/zYLwKGb?editors=0010 

MarceloRosensaft
New Contributor III

Thank you very much!

Your suggested option seems to be what I need.

I'm counting the features for each layer in the view and I have to count again every time the view changes. Today I do it with layerView.watch('updating'... for every layer and I also catch separately the visibility of the layers since the layerView doen't update when the layer not visible. With your option everything will be simpler. I'm starting to put it in my code.

Thanks again!

Marcelo

0 Kudos