Select to view content in your preferred language

Understanding Promise deprecation warnings in ArcGIS API for JavaScript?

2565
1
03-05-2018 02:45 PM
BrienCrean
New Contributor

I am trying to update legacy map code to the latest ArcGIS version of 4.6 and noticed this warning in the console when querying a feature layer.

[esri.core.Promise] DEPRECATED: then() -- use .when(callback, errback) instead

So I tried to change then to when, but got when is not a function errors. I also tried running the sample code from the site and got the same errors.

view.whenLayerView(featureLayer).then(function(lyrView) {
  lyrView.watch("updating", function(val) {
    if (!val) { // wait for the layer view to finish updating

    // query all the features available for drawing.
    lyrView.queryFeatures().then(function(results) {

      graphics = results;

      var fragment = document.createDocumentFragment();

      results.forEach(function(result, index) {
         var attributes = result.attributes;
         var name = attributes.ZIP + " (" +
         attributes.PO_NAME + ")"

         // Create a list zip codes in NY
         var li = document.createElement("li");
         li.classList.add("panel-result");
         li.tabIndex = 0;
         li.setAttribute("data-result-id", index);
         li.textContent = name;

         fragment.appendChild(li);
      });
      // Empty the current list
      listNode.innerHTML = "";
      listNode.appendChild(fragment);
      });
      }
   });
});

I also tried setting the "esri-promise-compatibility" flag to 1 but that didn't help. Can't see anything in the docs or community forums about this. Anyone come across this before?

Tags (1)
1 Reply
RodrigoFelga
Regular Contributor

You need to replace then for when just when a class resolve to a promise. I don't see in you code any point to change, maybe the warning came from inside the api. Also happend to me to see warnings that came from inside the api and I can't resolve.

Like

view.then(function(){});‍‍

To

view.when(function(){});‍‍

When a method resolve to a promise you don't need to change.

Read more here: Making Better Promises | ArcGIS Blog 

Here is a list of classes that have a then method: Overview | API Reference | ArcGIS API for JavaScript 4.6