lscharen

InfoWindowBase.setContent error for a function returning a new-style deferred

Discussion created by lscharen on Jan 30, 2013
I recently upgraded a project to the new 3.3 JSAPI release and, since it is based on Dojo 1.8, moved my use of deferred to the new Dojo 1.8 Promised API.  However, this broke some code that returned a deferred to the setContent method on the InfoWindow class.

Looking at the source code of the class, the InfoWindow class shows that is just calls the InfoWindowBase.__setValue method in its setConent implementation.

       
setContent: function (content) {
            this.destroyDijits(this._content);
            this.__setValue("_content", content);
            return this;
        }


The InfoWindowBase class' __setValue(name, value) method, it checks to see if the passed value is an instance of the "dojo.Deferred" class.  This test fails for new Dojo 1.8 deferred that are loaded from "dojo/Deferred" since dojo.Deferred is aliased to the "dojo/_base/Deferred" class.

          
if (esri._isDefined(value)) {
                if (value instanceof dojo.Deferred) {
                    this[dfd] = value;
                    value.addCallbacks(this["__set" + name], this["__err" + name]);
                } else {
                    this.__render(name, value);
                }
            }


I would suggest that, rather than testing for the hard-coded dojo.Deferred class, that the test be changed to look for a "then()" method on the passed value and using that function to register the callback and errback function, e.g.

          
if (esri._isDefined(value)) {
                if (typeof value.then == "function") {
                    this[dfd] = value;
                    value.then(this["__set" + name], this["__err" + name]);
                } else {
                    this.__render(name, value);
                }
            }


In the meantime, I have worked around this issue by requiring both the "dojo/Deferred" and "dojo/_base/Deferred" classes in my code and using the old-style deferred for setting deferred content to the InfoWindow object.

Outcomes