Replace the default angular $q service with the bluebird promise library for enhanced promises within your angular app!
Branch: master
Clone or download
mattlewis92 docs(readme): add unmaintained badge
I haven't actually used this module myself in years and have too many other repos to maintain.
Latest commit c7094d3 Apr 19, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist chore(release): 1.0.2 Aug 30, 2016
src docs: add note about overriding the onPossiblyUnhandledRejection call… Jan 11, 2016
test test(module-name): add test for commonjs module name Dec 16, 2015
.babelrc fix(commonjs): fix requiring the module with webpack + browserify. Cl… Dec 16, 2015
.editorconfig Add linting Apr 12, 2015
.eslintrc chore(dependencies): upgrade dev dependencies May 12, 2016
.gitignore Remove the need for the intermediate webpack folder Jul 1, 2015
.travis.yml Remove bluebird from dev deps, fix travis for real this time Oct 31, 2015
CHANGELOG.md chore(release): 1.0.2 Aug 30, 2016
LICENSE Initial commit Nov 10, 2014
README.md docs(readme): add unmaintained badge Apr 19, 2017
bower.json chore(release): 1.0.2 Aug 30, 2016
index.html Inline the webpack server Jul 5, 2015
karma.conf.js fix(commonjs): fix requiring the module with webpack + browserify. Cl… Dec 16, 2015
package.json chore(release): 1.0.2 Aug 30, 2016
webpack.config.babel.js chore(webpack): use babel for webpack config Feb 8, 2016
webpack.config.build.babel.js

README.md

Angular bluebird promises

project unmaintained Build Status Bower version npm version devDependency Status Codacy Badge

This is a drop in replacement for $q that makes the bluebird API compatible with angulars subset of $q then simply swaps it out.

With this module you can use all of bluebirds additional promise methods on the $q service, the full list can be found here:

http://bluebirdjs.com/docs/api-reference.html

Installation

The library depends on angularJS and Bluebird.

It is recommended that you install the library and its dependencies through bower:

bower install --save angular-bluebird-promises

You will then need to include the JS files for the plugin:

<script src="bower_components/bluebird/js/browser/bluebird.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-bluebird-promises/dist/angular-bluebird-promises.min.js">

And finally add the module dependency in your AngularJS app:

angular.module('myApp', ['mwl.bluebird']);

Alternatively you can install through npm:

npm install --save angular-bluebird-promises

Then add as a dependency to your app:

angular.module('myApp', [require('angular-bluebird-promises')]);

Usage

Simply use $q as you normally would. It will function exactly as before, however you will now have bluebirds additional API methods available as well on all promises throughout your angular app.

$q.all vs. bluebird Promise.all

The behavior of the $q.all(...) function is actually a combination of bluebird's Promise.props and Promise.all function depending on whether an object or an array is passed, respectively. This behavior is preserved such that calling $q.all with an object will pass through to Promise.props while calling it with an array will pass through to Promise.all.

Unhandled rejections

By default the value of onPossiblyUnhandledRejection is set to angular.noop. You can and should override this with your own handler in order to catch uncaught errors. For example:

angular.module('mwl.bluebird').run(function($q, $log) {
  $q.onPossiblyUnhandledRejection(function(err) {
    $log.warn('Unhandled rejection', err);
  });
});

If using the ui-router this will produce some noise. To get around this you can do something like:

$q.onPossiblyUnhandledRejection(function(exception) {
  if (exception.message.match(/transition (superseded|prevented|aborted|failed)/)) {
    return;
  }
  // Handle exception
});

Example

angular.module('mwl.example', ['mwl.bluebird']).run(function($q, $http) {

    var promises = [
        $http.get('test/angular.json'),
        $http.get('test/bluebird.json')
    ];

    //Note the use of spread which isn't available normally on $q
    $q.all(promises).spread(function(angular, bluebird) {

        console.info('\\m/ It worked! \\m/', angular.data.name, bluebird.data.name);

    }).catch(console.error);

});

Development

Prepare your environment

  • Install Node.js and NPM (should come with)
  • Install local dev dependencies: npm install while current directory is this repo

Build

Run npm run build to build the project files in the dist folder

Development server

Run npm start to start a development server with auto reload that will also run unit tests

License

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.