feat: providers

This commit is contained in:
cha0s 2020-12-20 12:10:42 -06:00
parent 0919093be4
commit 2d2625a3cb
2 changed files with 15 additions and 6 deletions

View File

@ -8,15 +8,20 @@ export {LatusContext, React};
export default {
hooks: {
'@latus/http/client/up': async (latus) => {
const Components = latus.invoke('@latus/react/components');
const Components = latus.invoke('@latus/react/client/components');
const Providers = await latus.invokeOrdered('@latus/react/client/providers');
const children = await Promise.all(
Object.entries(Components)
.map(async ([key, Component]) => React.createElement(await Component, {key})),
);
return render(
React.createElement(LatusContext.Provider, {value: latus}, children),
window.document.getElementById('root'),
);
const RootElement = [
[LatusContext.Provider, {value: latus}],
].concat(Providers)
.reverse()
.reduce((children, [Provider, props], i) => [
React.createElement(Provider, {key: `@latus/react/provider(${i})`, ...props}, children),
], children);
return render(RootElement[0], window.document.getElementById('root'));
},
},
};

View File

@ -53,13 +53,17 @@ const middleware = (neutrino) => {
export default {
hooks: {
'@latus/core/config': () => ({
'client.providers': [],
entry: './react',
}),
'@latus/http/build': (client) => {
client.use.push(middleware);
},
'@latus/http/plugins': (req, {config: {'@latus/react': {entry}}}) => ({
'@latus/http/plugins': (req, {
config: {'@latus/react': {'client.providers': providers, entry}},
}) => ({
[entry]: {},
'@latus/react/client': {providers},
}),
},
};