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

RFC: uniform steps #377

Closed
tripodsan opened this issue Jun 14, 2019 · 3 comments · Fixed by #440
Closed

RFC: uniform steps #377

tripodsan opened this issue Jun 14, 2019 · 3 comments · Fixed by #440

Comments

@tripodsan
Copy link
Contributor

tripodsan commented Jun 14, 2019

Overview

the current pipeline has a clear separation of before, once and after pipeline functions.
This allows to easily replace the once action, but requires the extension mechanism to inject other steps. this proposal tries to remove this distinction and make it easier to manipulate an existing pipeline.

Proposal

1. Uniform steps

Deprecate (or remove): before(), once(), after() in favour of a single use() method that constructs the pipeline. Since the old methods were used in sequence anyways, they can easily just be mapped to theuse() method.

/**
 * Adds a processing function to this pipeline.
 * @param {pipelineFunction} f function to add.
 * @returns {Pipeline} this
 */
use(f:pipelineFunction):Pipeline;

Example:

pipe
  .every(dump.record)
  .before(fetch).expose('fetch').when(hascontent)
  .before(parse).expose('parse')
  .before(html).expose('html')
  .once(cont)
  .after(type('text/html'))
  .after(addHeaders)
  .after(tohtml)
  .after(debug)
  .after(timer.report)
  .error(dump.report)
  .error(selectStatus)

just becomes:

pipe
  .every(dump.record)
  .use(fetch).expose('fetch').when(hascontent)
  .use(parse).expose('parse')
  .use(html).expose('html')
  .use(cont)
  .use(type('text/html'))
  .use(addHeaders)
  .use(tohtml)
  .use(debug)
  .use(timer.report)
  .error(dump.report)
  .error(selectStatus)

2. Support replacing steps

Sometimes it might be convenient to modify an existing default pipeline. This is already marginally possible using attach.before() and attach.after(). However, it should also be possible to replace existing steps.

/**
 * Replaces an existing handler of this pipeline. The function `fn` will be run in
 * the pipeline instead the function called `name`. If `fn` is {@code null}, the 
 * respective function is removed. 
 * If `name` does not exist, this method has no effect.
 * @param {string} name - name of the extension point (typically the function name).
 * @param {pipelineFunction} fn - a new pipeline step that will replace `name`.
 * @returns {Pipeline} this.
 */
replace(name:string, fn:pipelineFunction):Pipeline;

Example:

module.exports.defaultPipe = pipe
  .use(fetch).expose('fetch').when(hascontent)
  .use(parse).expose('parse')
  .use(html).expose('html')
  .use(defaultRenderer).expose('render')
  .use(tohtml)
  .use(debug)
  .error(selectStatus)

some where else...

const p = require('./defaultPipe');
p.replace('render', myCoolRenderer).run(...);
@tripodsan tripodsan added question Further information is requested discussion and removed question Further information is requested labels Jun 14, 2019
@trieloff
Copy link
Contributor

Let's do this.

@rofe
Copy link
Contributor

rofe commented Jun 14, 2019

👍 This would simplify things quite a bit.

@rofe rofe self-assigned this Aug 13, 2019
rofe added a commit that referenced this issue Aug 13, 2019
@rofe rofe closed this as completed in #440 Aug 22, 2019
rofe added a commit that referenced this issue Aug 22, 2019
BREAKING CHANGE: removed before(), once() and after() methods in favor of use()
- added new uniform method pipe.use()
- added new method pipe.attach.replace() to replace pipeline steps
- pipe.attach() now public API, accepts object with before, replace and after keys
- removed methods before(), once() and after()
adobe-bot pushed a commit that referenced this issue Aug 22, 2019
# [5.0.0](v4.1.0...v5.0.0) (2019-08-22)

### Features

* **pipe:** uniform steps ([#377](#377)) ([7d9f701](7d9f701))

### BREAKING CHANGES

* **pipe:** removed before(), once() and after() methods in favor of use()
- added new uniform method pipe.use()
- added new method pipe.attach.replace() to replace pipeline steps
- pipe.attach() now public API, accepts object with before, replace and after keys
- removed methods before(), once() and after()
@adobe-bot
Copy link

🎉 This issue has been resolved in version 5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

rofe added a commit that referenced this issue Aug 29, 2019
BREAKING CHANGE: removed before(), once() and after() methods in favor of use()
- added new uniform method pipe.use()
- added new method pipe.attach.replace() to replace pipeline steps
- pipe.attach() now public API, accepts object with before, replace and after keys
- removed methods before(), once() and after()
rofe pushed a commit that referenced this issue Aug 29, 2019
# [5.0.0](v4.1.0...v5.0.0) (2019-08-22)

### Features

* **pipe:** uniform steps ([#377](#377)) ([7d9f701](7d9f701))

### BREAKING CHANGES

* **pipe:** removed before(), once() and after() methods in favor of use()
- added new uniform method pipe.use()
- added new method pipe.attach.replace() to replace pipeline steps
- pipe.attach() now public API, accepts object with before, replace and after keys
- removed methods before(), once() and after()
rofe pushed a commit that referenced this issue Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants