fetchComponentData.ts 639 Bytes
Newer Older
Maxym Borodenko's avatar
Maxym Borodenko committed
1
2
3
4
5
6
7
8
9
10
11
export default function fetchComponentData(dispatch, branch, search) {
    const promisesWithProps = [];

    branch.map(({ route, match }) => {
        const component = route.component;

        if (!component || !component.needs) {
            return;
        }

        // Provide params to static needs
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
12
        component.needs.filter((need) => need({ search, params: match.params })).map((need) => {
Maxym Borodenko's avatar
Maxym Borodenko committed
13
14
15
            return dispatch(need({ search, params: match.params }));
        })
        // a nice array of Promises
16
        .forEach((promise) => promisesWithProps.push(promise));
Maxym Borodenko's avatar
Maxym Borodenko committed
17
18
19
20
    });

    return Promise.all(promisesWithProps);
}