I'm building a store locator and loading a custom module via require. The custom module is dependent on Directions & Search module from microsoft. I hate the callback hell and want to pre load the modules return a promise and action on the custom module once everything is loaded.
Using bluebird for Promise spec and I've tried several approaches Promise.method
, Promise.promisify
, new Promise(function(resolve, reject){Microsoft.Maps.loadModule({callback:resolve})})
I can't seem to get any of them working.
My latest implementation:
function loadSearch() {
var resolver = Promise.defer();
Microsoft.Maps.loadModule('Microsoft.Maps.Search', {
callback: resolver.resolve
});
return resolver.promise;
} /* end loadSearch */
function loadDirections() {
var resolver = Promise.defer();
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', {
callback: resolver.resolve
});
return resolver.promise;
}
Promise.all([loadSearch(), loadDirections()], function() {
//do something
});
results in Uncaught TypeError: Cannot read property '_tryFollow' of undefined bluebird.js
Can anyone point out what an obvious error in the latest code or a psuedo code example of loading modules in a promise fashion.