Skip to content

Commit cbc93b9

Browse files
committed
adjustments for how children are added when the prop was changed
1 parent 02bf1c8 commit cbc93b9

File tree

6 files changed

+39
-38
lines changed

6 files changed

+39
-38
lines changed

dash/dash-renderer/src/actions/callbacks.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ async function handleClientside(
336336

337337
function updateComponent(component_id: any, props: any, cb: ICallbackPayload) {
338338
return function (dispatch: any, getState: any) {
339-
const _state = getState()
340-
const {paths, config} = getState();
339+
const _state = getState();
340+
const {paths, config} = _state;
341341
const componentPath = getPath(paths, component_id);
342342
if (!componentPath) {
343343
if (!config.suppress_callback_exceptions) {
@@ -361,8 +361,7 @@ function updateComponent(component_id: any, props: any, cb: ICallbackPayload) {
361361
dispatch(
362362
updateProps({
363363
props,
364-
itempath: componentPath,
365-
state: _state
364+
itempath: componentPath
366365
})
367366
);
368367
dispatch(notifyObservers({id: component_id, props}));

dash/dash-renderer/src/observers/executedCallbacks.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const observer: IStoreObserverDefinition<IStoreState> = {
4545
} = getState();
4646

4747
function applyProps(id: any, updatedProps: any) {
48-
const _state = getState()
48+
const _state = getState();
4949
const {layout, paths} = _state;
5050
const itempath = getPath(paths, id);
5151
if (!itempath) {
@@ -69,8 +69,7 @@ const observer: IStoreObserverDefinition<IStoreState> = {
6969
updateProps({
7070
itempath,
7171
props,
72-
source: 'response',
73-
state: _state
72+
source: 'response'
7473
})
7574
);
7675

dash/dash-renderer/src/reducers/reducer.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {forEach, includes, isEmpty, keys, path, assoc, pathOr} from 'ramda';
22
import {combineReducers} from 'redux';
3-
import {batch} from 'react-redux';
43

54
import {getCallbacksByInput} from '../actions/dependencies_ts';
65

@@ -19,7 +18,7 @@ import layout from './layout';
1918
import paths from './paths';
2019
import callbackJobs from './callbackJobs';
2120
import loading from './loading';
22-
import {stringifyPath, getComponentLayout} from '../wrapper/wrapping';
21+
import {stringifyPath} from '../wrapper/wrapping';
2322

2423
export const apiRequests = [
2524
'dependenciesRequest',
@@ -29,28 +28,31 @@ export const apiRequests = [
2928
];
3029

3130
function adjustHashes(state, action) {
32-
const actionPath = action.payload.itempath
31+
const actionPath = action.payload.itempath;
3332
const strPath = stringifyPath(actionPath);
3433
const prev = pathOr(0, [strPath], state);
3534
state = assoc(strPath, prev + 1, state);
3635

3736
// check if children was adjusted
3837
if ('children' in pathOr({}, ['payload', 'props'], action)) {
39-
const children = pathOr({}, ['payload', 'props', 'children'], action)
40-
const basePath = [...actionPath, 'props', 'children']
38+
const children = pathOr({}, ['payload', 'props', 'children'], action);
39+
const basePath = [...actionPath, 'props', 'children'];
4140
if (Array.isArray(children)) {
4241
children.forEach((v, i) => {
43-
state = adjustHashes(state, { payload: { itempath: [...basePath, i], props: v?.props } });
44-
})
42+
state = adjustHashes(state, {
43+
payload: {itempath: [...basePath, i], props: v?.props}
44+
});
45+
});
4546
} else if (children) {
46-
state = adjustHashes(state, { payload: { itempath: basePath }, props: children?.props });
47+
state = adjustHashes(state, {
48+
payload: {itempath: [...basePath], props: children?.props}
49+
});
4750
}
48-
4951
}
50-
return state
52+
return state;
5153
}
5254

53-
const layoutHashes = batch(() => (state = {}, action) => {
55+
const layoutHashes = (state = {}, action) => {
5456
if (
5557
includes(action.type, [
5658
'UNDO_PROP_CHANGE',
@@ -63,7 +65,7 @@ const layoutHashes = batch(() => (state = {}, action) => {
6365
return adjustHashes(state, action);
6466
}
6567
return state;
66-
})
68+
};
6769

6870
function mainReducer() {
6971
const parts = {

dash/dash-renderer/src/utils/clientsideFunctions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ function set_props(
2626
dispatch(
2727
updateProps({
2828
props,
29-
itempath: componentPath,
30-
state: _state
29+
itempath: componentPath
3130
})
3231
);
3332
dispatch(notifyObservers({id: idOrPath, props}));

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ type DashWrapperProps = {
4343
_dashprivate_error?: any;
4444
};
4545

46-
4746
function DashWrapper({
4847
componentPath,
4948
_dashprivate_error,
@@ -69,13 +68,10 @@ function DashWrapper({
6968
dispatch((dispatch, getState) => {
7069
const currentState = getState();
7170
const {graphs} = currentState;
72-
const oldLayout = getComponentLayout(
73-
componentPath,
74-
currentState
75-
)
76-
if (!oldLayout) return
71+
const oldLayout = getComponentLayout(componentPath, currentState);
72+
if (!oldLayout) return;
7773
const {props: oldProps} = oldLayout;
78-
if (!oldProps) return
74+
if (!oldProps) return;
7975
const changedProps = pickBy(
8076
(val, key) => !equals(val, oldProps[key]),
8177
restProps
@@ -115,8 +111,7 @@ function DashWrapper({
115111
dispatch(
116112
updateProps({
117113
props: changedProps,
118-
itempath: componentPath,
119-
state: currentState
114+
itempath: componentPath
120115
})
121116
);
122117
});
@@ -381,7 +376,9 @@ function DashWrapper({
381376

382377
let hydratedChildren: any;
383378
if (componentProps.children !== undefined) {
384-
hydratedChildren = wrapChildrenProp(componentProps.children, ['children']);
379+
hydratedChildren = wrapChildrenProp(componentProps.children, [
380+
'children'
381+
]);
385382
}
386383

387384
const rendered = config.props_check ? (
@@ -390,17 +387,22 @@ function DashWrapper({
390387
props={hydratedProps}
391388
component={component}
392389
>
393-
{createElement(element, hydratedProps, extraProps, hydratedChildren)}
390+
{createElement(
391+
element,
392+
hydratedProps,
393+
extraProps,
394+
hydratedChildren
395+
)}
394396
</CheckedComponent>
395397
) : (
396398
createElement(element, hydratedProps, extraProps, hydratedChildren)
397399
);
398400

399-
return rendered
401+
return rendered;
400402
}, [h]);
401403

402404
if (!component) {
403-
return null
405+
return null;
404406
}
405407

406408
return (
@@ -415,7 +417,7 @@ function DashWrapper({
415417
dispatch={dispatch}
416418
>
417419
<DashContextProvider componentPath={componentPath}>
418-
{hydrated ? hydrated : <div/>}
420+
{hydrated ? hydrated : <div />}
419421
</DashContextProvider>
420422
</ComponentErrorBoundary>
421423
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export const selectDashProps =
1212
// Then it can be easily compared without having to compare the props.
1313
const strPath = stringifyPath(componentPath);
1414

15-
const h = state.layoutHashes[strPath]
15+
const h = state.layoutHashes[strPath];
1616
if (!c) {
17-
return [c, {}, -100]
17+
return [c, {}, -100];
1818
}
1919
return [c, c?.props, h];
2020
};
@@ -24,7 +24,7 @@ export function selectDashPropsEqualityFn(
2424
[___, ____, previousHash]: SelectDashProps
2525
) {
2626
// Only need to compare the hash as any change is summed up
27-
return (hash === previousHash);
27+
return hash === previousHash;
2828
}
2929

3030
export function selectConfig(state: any) {

0 commit comments

Comments
 (0)