Skip to content

Commit

Permalink
fix(RenderHandler): updates to context data post-render pushed update…
Browse files Browse the repository at this point in the history
…d data as subsequent args

affects: @tao.js/react

when a DataContext had its data updated from a signal causing a re-render of an already rendered
RenderHandler the updated data was being appended to the end or depending on how many contexts were
defined pushing all later data as additional data args to the RenderHandler's render child method.
This fix ensures all data args are positional and remain consistent throughout the life of the
RenderHandler.

Also add warning and null out a missing context from user error.
  • Loading branch information
eudaimos committed Feb 6, 2022
1 parent f9ec69e commit c5556ed
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/react-tao/src/RenderHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,34 @@ function recursiveContextGenerator(
tao,
data,
ctxIdx = 0,
ctxDataArgs = []
ctxDataArgs = null
) {
if (ctxDataArgs == null) {
ctxDataArgs = new Array(ctxList.length);
}
const ctxName = ctxList[ctxIdx];
const context = getContext(ctxName);
if (!context) {
console.warn(
`RenderHandler::Unable to find context for '${ctxName}'. Please check that you have it spelled correctly.`
);
console.info(`RenderHandler::setting context ${ctxName} data arg to null`);
ctxDataArgs[ctxIdx] = null;
return recursiveContextGenerator(
ctxList,
getContext,
children,
tao,
data,
ctxIdx + 1,
ctxDataArgs
);
}
if (ctxList.length > ctxIdx + 1) {
return (
<context.Consumer name={`${ctxName}.Consumer`}>
{ctxData => {
ctxDataArgs.push(ctxData);
ctxDataArgs[ctxIdx] = ctxData;
return recursiveContextGenerator(
ctxList,
getContext,
Expand All @@ -37,7 +56,7 @@ function recursiveContextGenerator(
return (
<context.Consumer name={`${ctxName}.Consumer`}>
{ctxData => {
ctxDataArgs.push(ctxData);
ctxDataArgs[ctxIdx] = ctxData;
return children(tao, data, ...ctxDataArgs);
}}
</context.Consumer>
Expand Down

0 comments on commit c5556ed

Please sign in to comment.