compose icon indicating copy to clipboard operation
compose copied to clipboard

add compose.hook or similar

Open tj opened this issue 11 years ago • 10 comments

some API for extending externally, for example the new debug stuff I just added could live in a different module. I'd like to provide a nicer alternative that outputs HTML documents since the terminal quickly becomes a clusterfuck, especially with parallel requests

tj avatar Dec 22 '13 16:12 tj

One thing I'm not sure about is what to call "events". The current debug code is using up and down but I'm not sure that is 100% clear to the end user. Client side talks about this as capturing and bubbling, but that doesn't seem right either. Is start and stop clear?

using on

var compose = require("koa-compse");

compose.on("down", function(ctx, name){ console.log(name, "has started"); });
compose.on("up", function(ctx, name){ console.log(name, "has finished"); });

using hook

var compose = require("koa-compse");

compose.hook(function(ctx, name, direction){
  if(direction=="down"){
    console.log(name, "has started");
  }
  else{
    console.log(name, "has finished");
  }
});

mcwhittemore avatar Dec 29 '13 19:12 mcwhittemore

we could implement it as more middleware that get injected inbetween, so you'd just do a normal yield. it feels super dirty to do this at the compose level though, I'd almost rather remove this library and have it be a thing in Koa. There's no guarantee that people will use compose() to compose middleware so unless we make it a formal thing it seems awkward

tj avatar Mar 13 '14 01:03 tj

I see the value of adding this to koa but how would koa inject debugging into something like compose?

On Wed, Mar 12, 2014 at 9:59 PM, TJ Holowaychuk [email protected]:

we could implement it as more middleware that get injected inbetween, so you'd just do a normal yield. it feels super dirty to do this at the compose level though, I'd almost rather remove this library and have it be a thing in Koa. There's no guarantee that people will use compose() to compose middleware so unless we make it a formal thing it seems awkward

Reply to this email directly or view it on GitHubhttps://github.com/koajs/compose/issues/6#issuecomment-37492228 .

mcwhittemore avatar Mar 14 '14 12:03 mcwhittemore

Implemented in #51 and #52

PlasmaPower avatar Mar 24 '16 17:03 PlasmaPower

Is there any consensus on this yet? I'd like to get an implementation merged.

PlasmaPower avatar Jun 06 '16 20:06 PlasmaPower

With the Koa v2 release in sight, I'd like to get a wrapper implementation merged. How should I work towards this goal?

PlasmaPower avatar Sep 07 '16 04:09 PlasmaPower

Is this still an open issue, or could there be consensus on the hope of node 8's experimental async_hook to rescue the situation soon enough?

fl0w avatar Jun 07 '17 22:06 fl0w

I think async_hook is more diagnostic oriented. While useful, I think wrappers will have other uses.

PlasmaPower avatar Jun 07 '17 22:06 PlasmaPower

Heh, yea. To be fair, that was the only use case I had in mind anyway.

fl0w avatar Jun 07 '17 22:06 fl0w

There is @feathersjs/hooks which allows hooking any async function, based on koa-compose.

bertho-zero avatar Apr 07 '21 18:04 bertho-zero