Skip to content

Commit

Permalink
fix: on render complete (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
miralemd committed Jan 15, 2020
1 parent 301c8aa commit 44d128c
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 116 deletions.
40 changes: 22 additions & 18 deletions apis/nucleus/src/components/Supernova.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,19 @@ const Supernova = ({ sn, snOptions: options, snContext, layout }) => {
}, []);

const render = () =>
component.render({
layout,
options,
context: {
permissions: (snContext || {}).permissions,
theme: (snContext || {}).theme,
rtl: (snContext || {}).rtl,
localeInfo: (snContext || {}).localeInfo,
logicalSize,
},
});
Promise.resolve(
component.render({
layout,
options,
context: {
permissions: (snContext || {}).permissions,
theme: (snContext || {}).theme,
rtl: (snContext || {}).rtl,
localeInfo: (snContext || {}).localeInfo,
logicalSize,
},
})
);

// Mount / Unmount
useEffect(() => {
Expand All @@ -96,20 +98,22 @@ const Supernova = ({ sn, snOptions: options, snContext, layout }) => {
// Skip render in selections
if (layout && layout.qSelectionInfo && layout.qSelectionInfo.qInSelections) return undefined;
if (renderCnt === 0) {
if (typeof options.onInitialRender === 'function') {
options.onInitialRender.call(null);
}
render();
setRenderCnt(renderCnt + 1);
render().then(() => {
if (typeof options.onInitialRender === 'function') {
options.onInitialRender.call(null);
}
setRenderCnt(renderCnt + 1);
});
} else {
// Debounce render
// TODO - consider requestAnimationFrame
if (renderDebouncer.current) {
clearTimeout(renderDebouncer.current);
}
renderDebouncer.current = setTimeout(() => {
render();
setRenderCnt(renderCnt + 1);
render().then(() => {
setRenderCnt(renderCnt + 1);
});
});
return () => clearTimeout(renderDebouncer.current);
}
Expand Down
Loading

0 comments on commit 44d128c

Please sign in to comment.