Sha256: dc93103caa5a5313116258880b16f0104340f4e2db45277bb2d78ed00124e63b
Contents?: true
Size: 1.54 KB
Versions: 6
Compression:
Stored size: 1.54 KB
Contents
; (function(angular) { 'use strict'; /** * Called with an array this acts like map, otherwise it acts like _.mapValues * in lodash. * @return {Array|Object} The same type as the input argument. */ var mapValues = function(obj, callback) { if (angular.isArray(obj)) return obj.map(callback) var ret = {} Object.keys(obj).forEach(function(key, val) { ret[key] = callback(obj[key], key) }) return ret } angular.module('ngPromiseExtras', []).config([ '$provide', function($provide) { $provide.decorator('$q', [ '$delegate', function($delegate) { var $q = $delegate $q.allSettled = function(promises) { return $q.all(mapValues(promises, function(promiseOrValue) { if (! promiseOrValue.then) return { state: 'fulfilled', value: promiseOrValue } return promiseOrValue.then(function(value) { return { state: 'fulfilled', value: value } }, function(reason) { return { state: 'rejected', reason: reason } }) })) } $q.map = function(values, callback) { return $q.all(mapValues(values, callback)) } $q.mapSettled = function(values, callback) { return $q.allSettled(mapValues(values, callback)) } /** * Like Bluebird.resolve. */ $q.resolve = function(value) { if (value && value.then) return value else return $q(function(resolve) { resolve(value) }) } return $q } ]) } ]) })(window.angular);
Version data entries
6 entries across 6 versions & 1 rubygems