FreeAllMedia/stimpak

Add .context feature

dcrockwell opened this issue · 1 comments

Currently, there are a lot of .binds to make this pattern work:

export default class StimpakProject {
    constructor(stimpak) {
        stimpak
            .logo(`Project Generator v${packageJson.version}`)
            .then(this.promptProjectBasicInformation.bind(this));
    }

    promptProjectBasicInformation(stimpak, done) {
        stimpak
            .use(StimpakProjectBasicInformation)
            .then(this.promptVersionControl.bind(this));

        done();
    }

    promptVersionControl(stimpak, done) {
        stimpak
            .use(StimpakVersionControl)
            .then(this.promptNpm.bind(this));
        done();
    }

    promptNpm(stimpak, done) {
        stimpak
            .use(StimpakNpm)
            .then(this.promptGithub.bind(this));
        done();
    }

    promptGithub(stimpak, done) {
        stimpak
            .use(StimpakGithub)
            .then(this.promptTranspiling.bind(this));
        done();
    }

    promptTranspiling(stimpak, done) {
        stimpak
            .use(StimpakTranspiling);
        done();
    }
}

We could add a .context(newContextObject) method to set the context for all internal steps.

stimpak.context(someObject);

stimpak.then(function (stimpak, done) {
    // this === someObject
});

Closed by #25