JSPM

wait.js

3.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q36177F
  • License MIT

JavaScript library to easily delay and chain class functions.

Package Exports

  • wait.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wait.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Wait.js

🖇️ JavaScript library to easily delay and chain class functions.

Gemnasium GitHub license GitHub release GitHub issues

Installation

npm i wait.js --save

Usage

Plug wait.js into your class:

import Wait from 'wait.js'

class MyClass {
    // step-1. Instantiate Wait.js and return "this" from your constructor:
    constructor () {
        this.w = Wait()
        return this
    }

    // step-2. Encapsulate each chainable function into the .handle() function:
    foo () {
        return this.w.handle(this, () => {
            /* Code here */
        })
    }
    bar () {
        return this.w.handle(this, () => {
            /* Code here */
        })
    }

    // step-3. Add a .pause() feature to your class:
    wait (milliseconds) {
        return this.w.pause(this, milliseconds)
    }
}

// step-4. It just works! You can now chain and delay your class functions:
const c = new MyClass()
c.foo().wait(2000).bar().foo()

Async functions

Wait.js also provides the ability to deal with async functions, by manually triggering the next execution:

import Wait from 'wait.js'

class MyClass {
    //..

    async () {
        // step-1. Add a "done" parameter to the encapsulating function
        // step-2. Manually call .done() when your async function is done
        return this.w.handle(this, (done) => {
            done()
        })
    }

    //..
}

// step-3. It just works! You can now chain and delay async functions:
const c = new MyClass()
c.foo().wait(2000).async().bar()

Contribution

npm run watch
npm run test

License

MIT © 2017 Sylvain Simao