Now, Please Meander

    vue-reactive-stateful-promise

    1.0.5 • Public • Published

    vue-reactive-stateful-promise

    Build coverage npm version dependencies

    Native Promise wrapper with reactive state getters (isPending, isResolved, isRejected).

    Installation

    npm install vue-reactive-stateful-promise
    

    Usage

    import StatefulPromise from 'vue-reactive-stateful-promise';

    Constructor

    Create a new promise the same way as you would with the Promise constructor:

      let p = new StatefulPromise((res, rej) => {
        // ...
      });
    
      p.isPending; // true
      p.isResolved; // false
      p.isRejected; // false

    Pass in an async function:

      let p = new StatefulPromise(async () => {
        // ...
      });
    
      p.isPending; // true
      p.isResolved; // false
      p.isRejected; // false

    Extend an existing promise:

      let pr = new Promise((resolve, reject) => {
        setTimeout(resolve, 10);
      });
    
      let p = new StatefulPromise(pr);
    
      p.isPending; // true
      p.isResolved; // false
      p.isRejected; // false

    Also works with Promise static methods:

      let p = StatefulPromise.resolve('foo');
    
      p.isPending; // false
      p.isResolved; // true
      p.isRejected; // false

    Options

    The constructor also accept options

      let p = new StatefulPromise((res, rej) => {
        setTimeout(res, 2000);
      }, {timeout: 1000, ignoreAbort: true});
      
      p.abort(); // This will do nothing
      
      p.catch((e) => {
        console.error(e); // Will return Error: Promise timed out
      });

    License

    This software is released under the terms of the GPL 3.0 license. See LICENSE.

    Install

    npm i vue-reactive-stateful-promise

    DownloadsWeekly Downloads

    26

    Version

    1.0.5

    License

    GPL-3.0

    Unpacked Size

    40.6 kB

    Total Files

    4

    Last publish

    Collaborators

    • tofandel