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