refactor: allow multiple providers

This commit is contained in:
cha0s 2021-03-31 10:36:03 -05:00
parent 97d90ee809
commit 913dc9786c

View File

@ -15,12 +15,17 @@ export default {
),
);
const Providers = await latus.invokeOrdered('@latus/react/providers');
const FlattenedProviders = [];
for (let i = 0; i < Providers.length; i++) {
const Provider = Providers[i];
FlattenedProviders.push(...(Array.isArray(Provider[0]) ? Provider : [Provider]));
}
const RootComponent = () => {
const children = Object.entries(Components)
.map(([key, Component]) => React.createElement(Component, {key}));
const RootElements = [
[LatusContext.Provider, {value: latus}],
].concat(Providers)
].concat(FlattenedProviders)
.reverse()
.reduce((children, [Provider, props], i) => [
// eslint-disable-next-line react/no-array-index-key