"update-end" event returns error but "onUpdateEnd" event doesn't

484
5
Jump to solution
06-26-2013 10:03 AM
KenBuja
MVP Esteemed Contributor
I have converted the code from using the "onUpdateEnd" event on an ArcGISDynamicMapServiceLayer to the class.on style event
 //before     connect.connect(layer, "onUpdateEnd", function (error) {         if (error) {             alert("Update complete with error: " & error);         }      });  //after     layer.on("update-end", function (error) {         if (error) {             alert("Update complete with error: " & error);         }      });


I am now getting an error returned for this event. I have created a Fiddle that shows this. Running the code with the "connect.connect" line (line 44) un-commented does not return an error, while the "layer.on" line (line 43) un-commented returns the error. Why is the error returned using this syntax?
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor
I think this has to do with how the error object is passed around using dojo/on.
Somewhere in the layer code there is now this.emit('update-end', errorObject);
But if you look at the error object itself, it's actually
{
  error: undefined,
  target: Object, // <- that target layer
  undefined: undefined // <- heh, probably has to do with some json and mixin stuff
}


Anyway, previously with connect.connect(layer, 'onUpdateEnd') it would pass nothing as an error object, so it looks like now you just need to check the returned error object to see if the error.error is undefined instead.

I hadn't run into this yet, but this is the behavior I'm seeing.
I'm guessing in the source for layer there is a method that handles this.emit('update-end', passedvariable) and it defaults to an object of some sort.

This is all best guess stuff since it isn't explicitly defined that this is the expected behavior in the docs/samples.

View solution in original post

0 Kudos
5 Replies
ReneRubalcava
Frequent Contributor
I think this has to do with how the error object is passed around using dojo/on.
Somewhere in the layer code there is now this.emit('update-end', errorObject);
But if you look at the error object itself, it's actually
{
  error: undefined,
  target: Object, // <- that target layer
  undefined: undefined // <- heh, probably has to do with some json and mixin stuff
}


Anyway, previously with connect.connect(layer, 'onUpdateEnd') it would pass nothing as an error object, so it looks like now you just need to check the returned error object to see if the error.error is undefined instead.

I hadn't run into this yet, but this is the behavior I'm seeing.
I'm guessing in the source for layer there is a method that handles this.emit('update-end', passedvariable) and it defaults to an object of some sort.

This is all best guess stuff since it isn't explicitly defined that this is the expected behavior in the docs/samples.
0 Kudos
KenBuja
MVP Esteemed Contributor
I had noticed that the error was returned with the additional "target" object when I was debugging the application. I was hoping the Esri JavaScript team would respond to this issue. Hopefully it will encourage them to update the documentation for the events using "on".
0 Kudos
JohnGravois
Frequent Contributor
as discussed in this article, when using the "on" method to connect events, a single event object is returned with event information contained within properties.  this is a deviation from the old "connect" style, which utilizes positional arguments (ie. callback(result) vs. errorback(error))

here's an example of checking to see if the onUpdateEnd event for a ArcGIS DynamicMapServiceLayer returned an error
layer.on("update-end", function (returnedEvent) {
    if (!returnedEvent.error == undefined){
        alert("Update complete with error: " + returnedEvent.error);
    }
});
0 Kudos
ReneRubalcava
Frequent Contributor
Ah, ok, missed that article.
The docs could probably use a tweak as they specify an Error object is returned, so that threw me off.
https://developers.arcgis.com/en/javascript/jsapi/layer-amd.html#onupdateend
0 Kudos
JohnGravois
Frequent Contributor
we should be able to get an example added to the doc shortly.  thanks guys!
0 Kudos