Select to view content in your preferred language

Popup Capture Close Event In 4.2x

1151
3
Jump to solution
06-01-2023 10:13 PM
PasiSavolainen
Emerging Contributor

In 4.25 I get this warning

[esri.core.watchUtils]

DEPRECATED - Module: esri/core/watchUtils

️ Replacement: esri/core/reactiveUtils
:gear:Version: 4.24

 

I have tried to use reactiveUtils but without success, the watchUtils example in 

https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popup-actions-capture-close-event...

works ok.

Here is the example that works and the other that I'm not able to get to work.

//works!
watchUtils.whenTrue(view.popup,'visible', () => {
	watchUtils.whenFalseOnce(view.popup,'visible', () => {
	  console.info('popup has been closed');
	})
});
//doesn't work
reactiveUtils.whenOnce(() => view.popup.visible).then(() => {
	reactiveUtils.whenOnce(() => !view.popup.visible).then(() => {
	  console.info('how to get here?');
	})
});

  A hybrid solution seems to work but I want to remove 'watchUtils' so it's not an option.

//this hybrid works
reactiveUtils.whenOnce(() => view.popup.visible).then(() => {
	watchUtils.whenFalseOnce(view.popup,'visible', () => {
	  console.info('popup has been closed');
	})
});

Any suggestions how to proceed?

Thanks

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Honored Contributor

If you just care about when the popup is closed, you don't need to capture when it's opened. You could, but it just depends on what you want to do.

when(
	() => view.popup?.visible,
	() => {
		whenOnce(() => !view.popup.visible).then(() =>
			console.log("Popup closed after opened")
		);
	}
);

// just capture when it closes
when(
	() => !view.popup?.visible,
	() => console.log("Popup closed")
);

https://codepen.io/odoe/pen/MWPNEyV?editors=1000

View solution in original post

3 Replies
ReneRubalcava
Honored Contributor

If you just care about when the popup is closed, you don't need to capture when it's opened. You could, but it just depends on what you want to do.

when(
	() => view.popup?.visible,
	() => {
		whenOnce(() => !view.popup.visible).then(() =>
			console.log("Popup closed after opened")
		);
	}
);

// just capture when it closes
when(
	() => !view.popup?.visible,
	() => console.log("Popup closed")
);

https://codepen.io/odoe/pen/MWPNEyV?editors=1000

PasiSavolainen
Emerging Contributor

Thanks! Both of these examples worked fine!😀

0 Kudos
UndralBatsukh
Esri Regular Contributor

This sample shows different ways of using reactiveUtils: https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=watch-for-changes-reacti...

If you want to watch a change only once then you can use reactiveUtils.whenOnce, please take a look at the doc and code snippets: https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html#whenOnce

 

0 Kudos