This package has been deprecated

Author message:

please use async/await instead

steps.js
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

stepsjs

The absolute simplest way to tame callback hell.

TypeScript Example Usage

import { Steps } from './steps';

new Steps([
  (Step) => {
      setTimeout(() => {
        console.log("Step 1 complete");
        Step.Next();
      });
  },
  (Step) => {
      setTimeout(() => {
        console.log("Step 2 complete");
        Step.Next();
      }, 1000);
  },
]);

JavaScript Example Usage

var Sequence = require('./steps');

new Sequence.Steps([
    function (Step) {
        setTimeout(function () {
            console.log("Step 1 complete");
            Step.Next();
        });
    },
    function (Step) {
        setTimeout(function () {
            console.log("Step 2 complete");
            Step.Next();
        }, 1000);
    },
]);

Complete Implementation in TypeScript

class Steps {
  private StepIndex = 0;

  public constructor(private StepArray: ((Step: Steps) => void)[]) {
    this.Next();
  }

  public Next() {
    if (this.StepIndex < this.StepArray.length) {
      this.StepArray[this.StepIndex++](this);
    }
  }
}

Building

The master source code file is in steps.ts located in the ts directory.

To build from the command line, run:

npm start

Package Sidebar

Install

npm i steps.js

Weekly Downloads

0

Version

1.1.0

License

MIT

Last publish

Collaborators

  • zzglenm