Add store the hook API

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2021-06-22 09:55:05 +02:00
parent 1288db6315
commit b675884e6f
2 changed files with 12 additions and 9 deletions

View File

@ -289,10 +289,11 @@ class StrapiApp {
runHookSeries = (name, asynchronous = false) =>
asynchronous ? this.hooksDict[name].runSeriesAsync() : this.hooksDict[name].runSeries();
runHookWaterfall = (name, initialValue, asynchronous = false) =>
asynchronous
? this.hooksDict[name].runWaterfallAsync(initialValue)
: this.hooksDict[name].runWaterfall(initialValue);
runHookWaterfall = (name, initialValue, asynchronous = false, store) => {
return asynchronous
? this.hooksDict[name].runWaterfallAsync(initialValue, store)
: this.hooksDict[name].runWaterfall(initialValue, store);
};
runHookParallel = name => this.hooksDict[name].runParallel();
@ -316,7 +317,9 @@ class StrapiApp {
menu={this.menu}
plugins={this.plugins}
runHookParallel={this.runHookParallel}
runHookWaterfall={this.runHookWaterfall}
runHookWaterfall={(name, initialValue, async = false) => {
return this.runHookWaterfall(name, initialValue, async, store);
}}
runHookSeries={this.runHookSeries}
settings={this.settings}
>

View File

@ -10,14 +10,14 @@ const createHook = () => {
delete(handler) {
_handlers.splice(_handlers.indexOf(handler), 1);
},
runWaterfall(args) {
return _handlers.reduce((acc, fn) => fn(acc), args);
runWaterfall(args, store) {
return _handlers.reduce((acc, fn) => fn(acc, store), args);
},
async runWaterfallAsync(args) {
async runWaterfallAsync(args, store) {
let result = args;
for (const fn of _handlers) {
result = await fn(result);
result = await fn(result, store);
}
return result;