tapable
tapable copied to clipboard
Do something with hook results
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}).
You could use a do/while loop for that.
@oofloren how would that work? There is no way to iterate hook subscribers, is there?
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
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?
I think all call* methods are private APIs. They are designed to be called by the code factories. Not user-land code.
So there is no way to achieve this without extending the public API?
On Tue, Mar 20, 2018 at 5:09 PM Florent Cailhol [email protected] wrote:
I think all call* methods are private APIs. They are designed to be called by the code factory. Not user-land code.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/webpack/tapable/issues/47#issuecomment-374656403, or mute the thread https://github.com/notifications/unsubscribe-auth/AADWlvABIV0pGkH90evPktrHcHpsYSFKks5tgSmggaJpZM4R5Mur .
The idea is to stop after the first subscriber that returns something specific.
The Bail hooks stop after the first plugin that returns something.
@sokra but that still doesn't allow checking for a specific value, and there's no way to wrap the hooks…
@wmertens you can use bail hook if the the value is just what you need, just return it.
@MoonYaph that would require wrapping all the subscribers to a hook and there's no way to do that.
@wmertens Hi!
Did you manage to find a solution to this issue? I'd like to do the same thing, as well.
@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