Skip to content

Commit d2e1ea1

Browse files
committed
adding tests for side updates
1 parent a0beaa4 commit d2e1ea1

File tree

4 files changed

+995
-26
lines changed

4 files changed

+995
-26
lines changed

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {createAction, Action} from 'redux-actions';
4141
import {addHttpHeaders} from '../actions';
4242
import {notifyObservers, updateProps} from './index';
4343
import {CallbackJobPayload} from '../reducers/callbackJobs';
44-
import {handlePatch, isPatch, parsePatchProps} from './patch';
44+
import {parsePatchProps} from './patch';
4545
import {computePaths, getPath} from './paths';
4646

4747
import {requestDependencies} from './requestDependencies';
@@ -818,12 +818,23 @@ export function executeCallback(
818818

819819
if (clientside_function) {
820820
try {
821-
const data = await handleClientside(
821+
let data = await handleClientside(
822822
dispatch,
823823
clientside_function,
824824
config,
825825
payload
826826
);
827+
// Patch methodology: always run through parsePatchProps for each output
828+
const currentLayout = getState().layout;
829+
flatten(outputs).forEach((out: any) => {
830+
const propName = cleanOutputProp(out.property);
831+
const outputPath = getPath(paths, out.id);
832+
const dataPath = [stringifyId(out.id), propName];
833+
const outputValue = path(dataPath, data);
834+
const oldProps = path(outputPath.concat(['props']), currentLayout) || {};
835+
const newProps = parsePatchProps({ [propName]: outputValue }, oldProps);
836+
data = assocPath(dataPath, newProps[propName], data);
837+
});
827838
return {data, payload};
828839
} catch (error: any) {
829840
return {error, payload};
@@ -882,26 +893,16 @@ export function executeCallback(
882893
dispatch(addHttpHeaders(newHeaders));
883894
}
884895
// Layout may have changed.
896+
// DRY: Always run through parsePatchProps for each output
885897
const currentLayout = getState().layout;
886898
flatten(outputs).forEach((out: any) => {
887899
const propName = cleanOutputProp(out.property);
888900
const outputPath = getPath(paths, out.id);
889-
const previousValue = path(
890-
outputPath.concat(['props', propName]),
891-
currentLayout
892-
);
893901
const dataPath = [stringifyId(out.id), propName];
894902
const outputValue = path(dataPath, data);
895-
if (isPatch(outputValue)) {
896-
if (previousValue === undefined) {
897-
throw new Error('Cannot patch undefined');
898-
}
899-
data = assocPath(
900-
dataPath,
901-
handlePatch(previousValue, outputValue),
902-
data
903-
);
904-
}
903+
const oldProps = path(outputPath.concat(['props']), currentLayout) || {};
904+
const newProps = parsePatchProps({ [propName]: outputValue }, oldProps);
905+
data = assocPath(dataPath, newProps[propName], data);
905906
});
906907

907908
if (dynamic_creator) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class PatchBuilder {
175175

176176
build() {
177177
return {
178-
__dash_patch_update: true,
178+
__dash_patch_update: "__dash_patch_update",
179179
operations: this.operations
180180
};
181181
}
@@ -304,7 +304,7 @@ export function handlePatch<T>(previousValue: T, patchValue: any): T {
304304
return reducedValue;
305305
}
306306

307-
export function parsePatchProps(props: any, previousProps: any): {} {
307+
export function parsePatchProps(props: any, previousProps: any): Record<string, any> {
308308
if (!is(Object, props)) {
309309
return props;
310310
}

0 commit comments

Comments
 (0)