Giter Site home page Giter Site logo

Comments (8)

meticoeus avatar meticoeus commented on May 18, 2024

One option for angular 1 projects would be to use the bluebird promise library. It exposes its scheduler which can then be tied to angular's digest cycle effciently.

The angular-bluebird-promises library takes care of the integration and replaces the $q service implementation with the bluebird implementation for you.

from legacy-ionic-cloud.

Maistho avatar Maistho commented on May 18, 2024

@meticoeus what is the advantage of using bluebird over the builtin $q?

Currently I wrap the promises with $q.all([promise]), but I'm not sure why... I should test $q.when(promise) instead, since that seems to be the preferred way to do it.

from legacy-ionic-cloud.

imhoffd avatar imhoffd commented on May 18, 2024

I guess bluebird adds more features? We don't need the additional features and I'd rather not have another dependency included in our bundle. We should be able to make use of $q to wrap our promises.

from legacy-ionic-cloud.

meticoeus avatar meticoeus commented on May 18, 2024

An option for a user of the library is to replace the global Promise from es6-promises (or native implementation) with bluebird promises. All uses of Promise in this and other libraries and your app code will be using a single implementation that can now inter-op with the digest cycle. You can then use the API directly instead of the wrapped versions, which may make sense in a project that is being migrated to angular 2. Just import ionic-cloud in the normal way.

from legacy-ionic-cloud.

imhoffd avatar imhoffd commented on May 18, 2024

Oh, I see! That native implementation replacement and digest cycle hook-in is something I've been wondering about. An option would be to document how to set up that library in Ionic 1 projects. We can't depend on it because our client must work for angular 1, Angular 2, and non-angular projects.

I personally think just wrapping the promises with angular's $q would be better because it's an api that angular devs are familiar with. It just seems more consistent. That way things work out of the box and we wouldn't need to require users to set up an additional library.

from legacy-ionic-cloud.

meticoeus avatar meticoeus commented on May 18, 2024

The $q wrapper approach is probably the best way to go to keep things simple and familiar for ng1 devs.

Documenting that you can and how setup bluebird so that you can avoid the wrapper might be useful for anyone doing a 1->2 migration so they can use the library directly without the ng1 modules.

from legacy-ionic-cloud.

meticoeus avatar meticoeus commented on May 18, 2024

For reference to anyone considering this strategy, there was already a discussion about making bluebird usable in angular 2 before they dropped $q for native promises.

The main take away is that $q is silent about uncaught promise rejections while bluebird is not. Some ng1 libraries like ui-router are guilty of this so your console will blow up until you change bluebird's configuration. Of course, that feature is useful when reviewing your own code.

from legacy-ionic-cloud.

imhoffd avatar imhoffd commented on May 18, 2024

@meticoeus @Maistho Got this working! If window.Promise is undefined, set it to $q, otherwise patch our use of promises with $q.when. πŸŽ‰

from legacy-ionic-cloud.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.