* Update a component props with `running`/`progress`/`set_props` calls. * * @param outputs Props to update. * @param cb The originating callback info. * @returns
(outputs: SideUpdateOutput, cb: ICallbackPayload)
| 394 | * @returns |
| 395 | */ |
| 396 | function sideUpdate(outputs: SideUpdateOutput, cb: ICallbackPayload) { |
| 397 | return function (dispatch: any, getState: any) { |
| 398 | toPairs(outputs) |
| 399 | .reduce((acc, [id, value], i) => { |
| 400 | let componentId = id, |
| 401 | propName, |
| 402 | replacedIds = []; |
| 403 | |
| 404 | if (id.startsWith('{')) { |
| 405 | [componentId, propName] = parsePMCId(id); |
| 406 | replacedIds = replacePMC(componentId, cb, i, getState); |
| 407 | } else if (id.includes('.')) { |
| 408 | [componentId, propName] = id.split('.'); |
| 409 | } |
| 410 | |
| 411 | const props = propName ? {[propName]: value} : value; |
| 412 | |
| 413 | if (replacedIds.length === 0) { |
| 414 | acc.push([componentId, props]); |
| 415 | } else if (replacedIds.length === 1) { |
| 416 | acc.push([replacedIds[0], props]); |
| 417 | } else { |
| 418 | replacedIds.forEach((rep: any) => { |
| 419 | acc.push([rep, props]); |
| 420 | }); |
| 421 | } |
| 422 | |
| 423 | return acc; |
| 424 | }, [] as any[]) |
| 425 | .forEach(([id, idProps]) => { |
| 426 | const state = getState(); |
| 427 | |
| 428 | const componentPath = getPath(state.paths, id); |
| 429 | let oldComponent = {props: {}}; |
| 430 | if (componentPath) { |
| 431 | oldComponent = getComponentLayout(componentPath, state); |
| 432 | } |
| 433 | |
| 434 | const oldProps = oldComponent?.props || {}; |
| 435 | |
| 436 | const patchedProps = parsePatchProps(idProps, oldProps); |
| 437 | |
| 438 | dispatch(updateComponent(id, patchedProps, cb)); |
| 439 | |
| 440 | if (!componentPath) { |
| 441 | // Component doesn't exist, doesn't matter just allow the |
| 442 | // callback to continue. |
| 443 | return; |
| 444 | } |
| 445 | |
| 446 | dispatch( |
| 447 | setPaths( |
| 448 | computePaths( |
| 449 | { |
| 450 | ...oldComponent, |
| 451 | props: {...oldComponent.props, ...patchedProps} |
| 452 | }, |
| 453 | [...componentPath], |
no test coverage detected
searching dependent graphs…