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

Commit

Permalink
refactor(pipe): more intutive offsets in attachGeneric
Browse files Browse the repository at this point in the history
  • Loading branch information
rofe committed Aug 16, 2019
1 parent 98c1485 commit d9fcb8d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Pipeline {
* Registers an extension to the pipeline.
* @param {String} name - name of the extension point (typically the function name).
* @param {pipelineFunction} f - a new pipeline step that will be injected relative to `name`.
* @param {integer} offset - where to insert the new function (-1: replace, 0: before, 1: after)
* @param {integer} offset - where to insert the new function (-1: before, 0: replace, 1: after)
*/
const attachGeneric = (name, f, offset) => {
// find the index of the function where the resolved ext name
Expand All @@ -126,7 +126,7 @@ 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 < 0) {
if (offset === 0) {
// replace
this._steps.splice(foundstep, 1, f);
} else if (offset > 0) {
Expand All @@ -147,7 +147,7 @@ class Pipeline {
* @param {String} name - name of the extension point (typically the function name).
* @param {pipelineFunction} f - a new pipeline step that will be injected relative to `name`.
*/
this.attach.before = (name, f) => attachGeneric.bind(this)(name, f, 0);
this.attach.before = (name, f) => attachGeneric.bind(this)(name, f, -1);
/**
* Registers an extension to the pipeline. The function `f` will be run in
* the pipeline after the function called `name` will be executed. If `name`
Expand All @@ -163,7 +163,7 @@ class Pipeline {
* @param {String} name - name of the extension point (typically the function name).
* @param {pipelineFunction} f - a new pipeline step that will replace `name`.
*/
this.attach.replace = (name, f) => attachGeneric.bind(this)(name, f, -1);
this.attach.replace = (name, f) => attachGeneric.bind(this)(name, f, 0);
}

/**
Expand Down

0 comments on commit d9fcb8d

Please sign in to comment.