Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
refactor(pipe): removed before() and after()
Browse files Browse the repository at this point in the history
BREAKING CHANGE: removed before() and after() methods in favor of use()
  • Loading branch information
rofe committed Aug 14, 2019
1 parent e134194 commit 98c1485
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
29 changes: 7 additions & 22 deletions src/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,15 @@ class Pipeline {
// if something has been found in the list, insert the
// new function into the list, with the correct offset
if (foundstep !== -1) {
if (offset === -1) {
if (offset < 0) {
// replace
this._steps.splice(foundstep, 1, f);
} else if (offset > 0) {
// insert after
this._steps.splice(foundstep + 1, 0, f);
} else {
this._steps.splice(foundstep + offset, 0, f);
// insert before (default)
this._steps.splice(foundstep, 0, f);
}
} else {
this._action.logger.warn(`Unknown extension point ${name}`);
Expand Down Expand Up @@ -173,26 +178,6 @@ class Pipeline {
return this;
}

/**
* Adds a processing function to the `pre` list of this pipeline.
* @param {pipelineFunction} f function to add to the `pre` list
* @returns {Pipeline} this
* @deprecated Call use() instead
*/
before(f) {
return this.use(f);
}

/**
* Adds a processing function to the `post` list of this pipeline.
* @param {pipelineFunction} f function to add to the `post` list
* @returns {Pipeline} this
* @deprecated Call use() instead
*/
after(f) {
return this.use(f);
}

/**
* Adds a tap (observing) function to the pipeline. taps are executed for every
* single pipeline step and best used for validation, and logging. taps don't have
Expand Down
4 changes: 2 additions & 2 deletions test/testPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ describe('Testing Pipeline', () => {
const order = [];
await new Pipeline({ logger })
.use(() => { order.push('pre0'); })
.before(() => { order.push('pre1'); }) // test deprecated before()
.use(() => { order.push('pre1'); })
.once(() => { order.push('once'); })
.use(() => { order.push('post0'); })
.after(() => { order.push('post1'); }) // test deprecated after()
.use(() => { order.push('post1'); })
.run();
assert.deepEqual(order, ['pre0', 'pre1', 'once', 'post0', 'post1']);
});
Expand Down

0 comments on commit 98c1485

Please sign in to comment.