mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Add store the hook API
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
1288db6315
commit
b675884e6f
@ -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}
|
||||
>
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user