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

idea: allow injecting wrappers to support different async paradigms #145

Closed
yoshuawuyts opened this issue Jul 8, 2016 · 3 comments
Closed

Comments

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Jul 8, 2016

I'm a huge fan of pull-stream, and would love to have it be a first-class citizen in choo. But I know that people can be picky about their preferences for async paradigms, so I reckon the best solution would be to add some sort of wrapping hook so choo can be extended to accomodate all flavors of async at no extra cost.

I reckon the API could be something like:

// each wrapper expects a function to be returned
app({
  wrapSubscriptions: (fn) => {},
  wrapReducers: (fn) => {},
  wrapEffects: (fn) => {}
})

With a little node core streams example (as that's the paradigm I'm most comfortable with):

const from = require('from2')
const pump = require('pump')

const app = choo({
  wrapEffect: (fn) => {
    return (data, state, send, done) => {
      const source = from(data)
      const sink = fn(state, send)
      pump(source, sink, (err, res) => {
        if (err) return done(err)
        done(null, res)
      })
    }
  }
})

Lil consideration I have if the API names should be plural or singular. Also if this idea makes sense at all, hah 😛 - reckon if done well enough it could ease up some of the (unfortunately necessary) rough edges around async that were introduced in v3. Thanks! ✨

@timwis
Copy link
Member

timwis commented Jul 12, 2016

Would run-series/run-parallel be another use case? Haven't used pull streams before so just trying to visualize.

@yoshuawuyts
Copy link
Member Author

@timwis run-series / run-parallel operate on callbacks, so they should be fine in the current setup I reckon. Other stuff could for example be a Promise wrapper, or async / await (though I refuse to ever let any Promise / a/a examples slip in haha)

@yoshuawuyts
Copy link
Member Author

This was added in [email protected] 🎉 - closing!

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

No branches or pull requests

2 participants