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

Do something with hook results #47

Open
wmertens opened this issue Feb 5, 2018 · 12 comments
Open

Do something with hook results #47

wmertens opened this issue Feb 5, 2018 · 12 comments

Comments

@wmertens
Copy link
Contributor

wmertens commented Feb 5, 2018

In my app, I would like to return early if one of the hooks returns some specific value. Would that be possible?

So for example hook.callUntil({args: [...], condition: result => result.foo}).

@ooflorent
Copy link
Member

You could use a do/while loop for that.

@wmertens
Copy link
Contributor Author

wmertens commented Feb 8, 2018

@oofloren how would that work? There is no way to iterate hook subscribers, is there?

@ooflorent
Copy link
Member

Sorry, the notification got lost!

let result
do {
  result = hook.call()
} while (result.foo)

We use a similar technique in webpack:

https://github.com/webpack/webpack/blob/3024078e1e8ec3df00020acad2e2de8b199b27fc/lib/Compilation.js#L828-L834

@wmertens
Copy link
Contributor Author

No, that calls all subscribers. The idea is to stop after the first subscriber that returns something specific.

is that what callTapsSeries does, can that be called directly?

@ooflorent
Copy link
Member

ooflorent commented Mar 20, 2018

I think all call* methods are private APIs. They are designed to be called by the code factories. Not user-land code.

@wmertens
Copy link
Contributor Author

wmertens commented Mar 20, 2018 via email

@sokra
Copy link
Member

sokra commented Nov 27, 2018

The idea is to stop after the first subscriber that returns something specific.

The Bail hooks stop after the first plugin that returns something.

@wmertens
Copy link
Contributor Author

@sokra but that still doesn't allow checking for a specific value, and there's no way to wrap the hooks…

@kisoua
Copy link

kisoua commented May 31, 2019

@wmertens you can use bail hook if the the value is just what you need, just return it.

@wmertens
Copy link
Contributor Author

@moonyaph that would require wrapping all the subscribers to a hook and there's no way to do that.

@Telokis
Copy link

Telokis commented Apr 20, 2020

@wmertens Hi!

Did you manage to find a solution to this issue?
I'd like to do the same thing, as well.

@wmertens
Copy link
Contributor Author

@Telokis I ended up rewriting it with a similar API but without all the browser optimizations.

https://github.com/StratoKit/strato-runner/blob/new-new-config/packages/launcher/src/tapable.js

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

5 participants