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

Commit

Permalink
feat: Pipeline now supports pipeline steps that mutate the input
Browse files Browse the repository at this point in the history
Just set .does_mutate=true on the function.

Bandaid for #223
  • Loading branch information
koraa committed Mar 28, 2019
1 parent 2c3669d commit 2b6ddf0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ class Pipeline {
}

// copy the pipeline payload into a new object to avoid modifications
// TODO: Better way of write-protecting the args for tapped functions; this may lead
// to weird bugs in user's code because modification seems to work but in
// fact the modification results are ignored; this one also has the draw
// TODO: This is also inefficient
// TODO: This also only works for objects and arrays; any data of custom type (e.g. DOM)
// is overwritten
const mergedargs = _.merge({}, currContext);
const tapresults = this._taps.map((f) => {
try {
Expand All @@ -350,7 +356,7 @@ class Pipeline {
return Promise.all(tapresults)
.then(() => Promise.resolve(currFunction(mergedargs, this._action))
.then((value) => {
const result = _.merge(currContext, value);
const result = currFunction.does_mutate ? mergedargs : _.merge(currContext, value);
this._action.logger.silly('received ', { function: this.describe(currFunction), result });
return result;
})).catch((e) => {
Expand Down

0 comments on commit 2b6ddf0

Please sign in to comment.