Skip to content

Add Patch callbacks #2414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
54f224b
Add patch API to partially update props from callbacks.
T4rk1n Jan 25, 2023
967d20b
Add unit tests for patch API.
T4rk1n Jan 25, 2023
f9c29b1
Remove PatchOutput, add allow_duplicate argument to Output.
T4rk1n Jan 26, 2023
f77cef2
Fix DAG with allow_duplicate.
T4rk1n Feb 1, 2023
5930963
Handle PMC patch outputs.
T4rk1n Feb 1, 2023
8a90e23
Fix patch handling logic.
T4rk1n Feb 1, 2023
7fbc630
Validate patch on undefined.
T4rk1n Feb 2, 2023
4ceb35d
Add integration tests for patch callbacks.
T4rk1n Feb 6, 2023
63466ec
Merge branch 'dev' into patch-update
T4rk1n Feb 6, 2023
5ba249c
Clean DAG output id infobox.
T4rk1n Feb 15, 2023
535c552
Merge branch 'dev' into patch-update
T4rk1n Feb 15, 2023
6cbad7e
Merge branch 'dev' into patch-update
T4rk1n Feb 20, 2023
88cdad4
Validate allow_duplicate with prevent_initial_call.
T4rk1n Feb 20, 2023
0c45291
Add patch insert.
T4rk1n Feb 28, 2023
ea3fb07
list or tuple
T4rk1n Feb 28, 2023
8610554
Merge branch 'dev' into patch-update
T4rk1n Feb 28, 2023
aefeb78
Error on patch with slice index.
T4rk1n Feb 28, 2023
3f9723c
Validate slice on deletion.
T4rk1n Feb 28, 2023
0c99886
Handle negative index in location.
T4rk1n Feb 28, 2023
280e948
Fix negative location index + support insert.
T4rk1n Feb 28, 2023
5b59c1c
Test array index deletion.
T4rk1n Feb 28, 2023
5e6c3a6
Remove regular +-*/ operations.
T4rk1n Feb 28, 2023
a7cb1d8
iadd to extend lists & merge dicts
T4rk1n Feb 28, 2023
e127080
Add clear operation.
T4rk1n Feb 28, 2023
1e5acb7
add ior to merge.
T4rk1n Feb 28, 2023
9f55b3d
Fix selenium keys import.
T4rk1n Mar 1, 2023
c5d4dd6
Add reverse
T4rk1n Mar 1, 2023
9ccc456
item->assigned
T4rk1n Mar 1, 2023
d4d8804
Rename merge to update
T4rk1n Mar 1, 2023
1fc6b46
Add remove.
T4rk1n Mar 1, 2023
9d4ae67
Add docstrings to patch methods.
T4rk1n Mar 1, 2023
d376745
Update dash/_patch.py
T4rk1n Mar 1, 2023
3fae39e
Add sort stub
T4rk1n Mar 1, 2023
2949b7b
Update changelog
T4rk1n Mar 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix patch handling logic.
  • Loading branch information
T4rk1n committed Feb 1, 2023
commit 8a90e237d74f7e6d8a387ea803398794d2d6a29e
25 changes: 15 additions & 10 deletions dash/dash-renderer/src/actions/callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {createAction, Action} from 'redux-actions';
import {addHttpHeaders} from '../actions';
import {notifyObservers, updateProps} from './index';
import {CallbackJobPayload} from '../reducers/callbackJobs';
import {handlePatch} from './patch';
import {handlePatch, isPatch} from './patch';
import {getPath} from './paths';

export const addBlockedCallbacks = createAction<IBlockedCallback[]>(
Expand Down Expand Up @@ -701,22 +701,27 @@ export function executeCallback(
if (newHeaders) {
dispatch(addHttpHeaders(newHeaders));
}
// Layout may have changed.
const currentLayout = getState().layout;
flatten(outputs).forEach((out: any) => {
const propName = out.property.split('@')[0];
const outputPath = getPath(paths, out.id);
const previousValue = path(
outputPath.concat(['props', propName]),
layout
currentLayout
);
const dataPath = [stringifyId(out.id), propName];
data = assocPath(
dataPath,
handlePatch(
previousValue,
path(dataPath, data)
),
data
);
const outputValue = path(dataPath, data);
if (
previousValue !== undefined &&
isPatch(outputValue)
) {
data = assocPath(
dataPath,
handlePatch(previousValue, outputValue),
data
);
}
});

return {data, payload};
Expand Down
5 changes: 1 addition & 4 deletions dash/dash-renderer/src/actions/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type PatchOperation = {
type LocationIndex = string | number;
type PatchHandler = (previous: any, patchUpdate: PatchOperation) => any;

function isPatch(obj: any): boolean {
export function isPatch(obj: any): boolean {
return has('__dash_patch_update', obj);
}

Expand Down Expand Up @@ -107,9 +107,6 @@ const patchHandlers: {[k: string]: PatchHandler} = {
};

export function handlePatch<T>(previousValue: T, patchValue: any): T {
if (!isPatch(patchValue)) {
return patchValue;
}
let reducedValue = previousValue;

for (let i = 0; i < patchValue.operations.length; i++) {
Expand Down