Skip to content

Commit 9c8a62a

Browse files
committed
adding renderType but making it a conditional prop that the component can subscribe to based upon its prop definitions
1 parent 889b4a5 commit 9c8a62a

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

dash/dash-renderer/src/wrapper/DashWrapper.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import {DashConfig} from '../config';
2424
import {notifyObservers, onError, updateProps} from '../actions';
2525
import {getWatchedKeys, stringifyId} from '../actions/dependencies';
2626
import {recordUiEdit} from '../persistence';
27-
import {createElement, getComponentLayout, isDryComponent} from './wrapping';
27+
import {
28+
createElement,
29+
getComponentLayout,
30+
isDryComponent,
31+
checkRenderTypeProp
32+
} from './wrapping';
2833
import Registry from '../registry';
2934
import isSimpleComponent from '../isSimpleComponent';
3035
import {
@@ -72,7 +77,7 @@ function DashWrapper({
7277

7378
// Select both the component and it's props.
7479
// eslint-disable-next-line prefer-const
75-
let [component, componentProps, h, changedProps] = useSelector(
80+
let [component, componentProps, h, changedProps, renderType] = useSelector(
7681
selectDashProps(componentPath),
7782
selectDashPropsEqualityFn
7883
);
@@ -215,7 +220,15 @@ function DashWrapper({
215220
const extraProps = {
216221
setProps,
217222
...extras
218-
};
223+
} as {[key: string]: any};
224+
225+
if (checkRenderTypeProp(component)) {
226+
extraProps['renderType'] = newRender.current
227+
? 'parent'
228+
: changedProps
229+
? renderType
230+
: 'parent';
231+
}
219232

220233
const setHydratedProps = (component: any, componentProps: any) => {
221234
// Hydrate components props

dash/dash-renderer/src/wrapper/wrapping.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import {mergeRight, path, type, has, join} from 'ramda';
2+
import {mergeRight, path, type, has, join, pathOr} from 'ramda';
33
import {DashComponent, DashLayoutPath} from '../types/component';
44

55
export function createElement(
@@ -61,3 +61,18 @@ export function getComponentLayout(
6161
): DashComponent {
6262
return path(componentPath, state.layout) as DashComponent;
6363
}
64+
65+
export function checkRenderTypeProp(componentDefinition: any) {
66+
return (
67+
'renderType' in
68+
pathOr(
69+
{},
70+
[
71+
componentDefinition?.namespace,
72+
componentDefinition?.type,
73+
'propTypes'
74+
],
75+
window as any
76+
)
77+
);
78+
}

0 commit comments

Comments
 (0)