Skip to content

Commit 57746d8

Browse files
committed
allows for parents to listen to descendent updates
1 parent 76a8e16 commit 57746d8

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

components/dash-core-components/src/components/Tabs.react.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,5 @@ Tabs.propTypes = {
439439
*/
440440
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
441441
};
442+
443+
Tabs.childrenLayoutHashes = true

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
import {DashLayoutPath, DashComponent, BaseDashProps} from '../types/component';
2-
import {getComponentLayout, stringifyPath} from './wrapping';
2+
import {getComponentLayout, stringifyPath, checkChildrenLayoutHashes} from './wrapping';
3+
import {pathOr} from 'ramda'
34

45
type SelectDashProps = [DashComponent, BaseDashProps, number, object, string];
56

7+
interface ChangedPropsRecord {
8+
hash: number;
9+
changedProps: Record<string, any>;
10+
renderType: string;
11+
}
12+
13+
const previousHashes = {}
14+
15+
function determineChangedProps(state: any, strPath: string): ChangedPropsRecord {
16+
let combinedHash = 0;
17+
let renderType = 'update'; // Default render type, adjust as needed
18+
Object.entries(state.layoutHashes).forEach(([updatedPath, pathHash]) => {
19+
if (updatedPath.startsWith(strPath)) {
20+
const previousHash: any = pathOr({}, [updatedPath], previousHashes);
21+
combinedHash += pathOr(0, ['hash'], pathHash)
22+
if (previousHash !== pathHash) {
23+
previousHash[updatedPath] = pathHash
24+
}
25+
}
26+
});
27+
28+
return {
29+
hash: combinedHash,
30+
changedProps: {},
31+
renderType
32+
};
33+
}
34+
635
export const selectDashProps =
736
(componentPath: DashLayoutPath) =>
837
(state: any): SelectDashProps => {
@@ -12,7 +41,12 @@ export const selectDashProps =
1241
// Then it can be easily compared without having to compare the props.
1342
const strPath = stringifyPath(componentPath);
1443

15-
const hash = state.layoutHashes[strPath];
44+
let hash;
45+
if (checkChildrenLayoutHashes(c)) {
46+
hash = determineChangedProps(state, strPath)
47+
} else {
48+
hash = state.layoutHashes[strPath];
49+
}
1650
let h = 0;
1751
let changedProps: object = {};
1852
let renderType = '';

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ export function checkRenderTypeProp(componentDefinition: any) {
7272
)
7373
);
7474
}
75+
76+
export function checkChildrenLayoutHashes(componentDefinition: any) {
77+
return (
78+
'childrenLayoutHashes' in
79+
pathOr(
80+
{},
81+
[componentDefinition?.namespace, componentDefinition?.type],
82+
window as any
83+
)
84+
);
85+
}

0 commit comments

Comments
 (0)