segmentio / ware

Easily create your own middleware layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

allow passing arrays

ianstormtaylor opened this issue · comments

to use and to the constructor, so that say you already have a bunch of validators you can just do:

ware(validators).run(val, function (err) {
  ...
});

if you wanted to get real fancy you could even accept a run callback in the constructor too

Ware(validators, function (err) {
  ...
});

@calvinfo whachu think? kinda cool in that it makes it completely functional if you wanted, or you can still use it as a stateful constructor

yup, lgtm. though I still kinda prefer the .use syntax since it seems a bit more explicit, and you can still compose ware instances if you'd like.

maybe you could even return the run function if you only pass a single arg. could be sweet for cases like this:

var auth = [loggedInUser, loggedInOrganization, someRandomthing, foo];
var validators = [...];
var processing = [...];

ware()
  .use(ware(auth))
  .use(ware(validators))
  .use(ware(processing));

though at that point, I guess .use() could just accept an array too

that's sweet. it could also just check instanceof Ware there and reach into .fns

just ran into this again