Hi,
I have a situation when I query Editor widget's element after it's added to the the map
const widgetDom = document.getElementsByClassName('esri-editor')[0];
In case when I do it after a while the page was loaded it happens successfully. But when I do right after the page is loaded (also after Editor widget is added to the view) it returns "undefined". I don't get what's the difference. Why it works fine in one case but doesn’t in another. Is there any event I can subscribe to make sure the widget is added to the DOM?
Yes, when is the answer 🙂
when() may be leveraged once an instance of the class is created.
// Although this example uses the BasemapGallery widget, any class instance that is a promise may use when() in the same way let bmGallery = new BasemapGallery(); bmGallery.when(function(){ // This function will execute once the promise is resolved }, function(error){ // This function will execute if the promise is rejected due to an error });
Does this solve the issue?
Egge-Jan
Yeah, thank you, it kind of resolves my issue. But for me it seems that callback inside editor.when(() => {})
doesn't really invokes after something was done about editor widget.
I tried to subscribe in different places
// I did on page load
const editor = new Editor({
view: view,
id: EDITOR_ID,
});
editor.when(() => {
console.log(1);
});
// then in on button click
view.ui.add(editor, position);
// and again
editor.when(() => {
console.log(2);
});
// and just for testing nothing doing with editor after button click
setTimeout(() => {
editorWidget.when(() => {
console.log(3);
});
}, 5000);
// Each callback happend ones, and in console I got output 1, 2, 3
I hope you get sequence of action I was doing. For me in such case feels like when is acting the same as setTimeout.