Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge in context with base property #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

amorev
Copy link
Contributor

@amorev amorev commented Jun 1, 2020

Idea of improvement

If we create stage with reusable function, we'll meet problem with "props already exists". I made small improvement by adding property to configuration of stageFunction.

Example

Now we can merge context of same functions

Code

const createPipeline = require('./easy-pipeline/src/index')
const stageA = name => {
  const stage = context => {
    if (context.props.bar) {
      return { bara: 'b' }
    } else
      return { bar: 'b' }
  }
  stage.config = { name }
  stage.config.useNameAsObject = true

  return stage
}

createPipeline(stageA('test'), stageA('test2'))().fork(err => console.error(err), r => console.log(r))

Result

So after this we'll receive such result:

{ test: { bar: 'b' }, test2: { bar: 'b' } }

Where to use

As you can see, there is no problem with same logic but different names. I would like to use your pipeline, for example, for telegram bot integration. I'll have stage "sendMessage", which returns telegram bot api's result.

I want to be able to call this stage multiple times in single pipelines and use result of every execution in context and have possibility to use it

Small (really big) problem

I can't make your tests passing. Even without my updates tests
check/easy-pipeline/test/index.js:329
and
check/easy-pipeline/test/index.js:336

Are failing and I can't understand that's wrong.

Thank you!

Now we can use stage config property useNameAsObject and add a result as new property to context. Usefull if we have multiple similar task with different results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant