* Set the props of a dash component by id or path. * * @param idOrPath Path or id of the dash component to update. * @param props The props to update.
(
idOrPath: string | object | string[],
props: {[k: string]: any}
)
| 11 | * @param props The props to update. |
| 12 | */ |
| 13 | function set_props( |
| 14 | idOrPath: string | object | string[], |
| 15 | props: {[k: string]: any} |
| 16 | ) { |
| 17 | const ds = getStores(); |
| 18 | for (let y = 0; y < ds.length; y++) { |
| 19 | const {dispatch, getState} = ds[y]; |
| 20 | let componentPath; |
| 21 | const state = getState(); |
| 22 | if (!Array.isArray(idOrPath)) { |
| 23 | componentPath = getPath(state.paths, idOrPath); |
| 24 | } else { |
| 25 | componentPath = idOrPath; |
| 26 | } |
| 27 | const oldComponent = getComponentLayout(componentPath, state); |
| 28 | |
| 29 | // Handle any patch props |
| 30 | props = parsePatchProps(props, oldComponent?.props || {}); |
| 31 | |
| 32 | // Update the props |
| 33 | dispatch( |
| 34 | updateProps({ |
| 35 | props, |
| 36 | itempath: componentPath, |
| 37 | renderType: 'clientsideApi' |
| 38 | }) |
| 39 | ); |
| 40 | dispatch(notifyObservers({id: idOrPath, props})); |
| 41 | |
| 42 | if (!oldComponent) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | dispatch( |
| 47 | setPaths( |
| 48 | computePaths( |
| 49 | { |
| 50 | ...oldComponent, |
| 51 | props: {...oldComponent.props, ...props} |
| 52 | }, |
| 53 | [...componentPath], |
| 54 | state.paths, |
| 55 | state.paths.events |
| 56 | ) |
| 57 | ) |
| 58 | ); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Clean url code adapted from https://github.com/braintree/sanitize-url/blob/main/src/constants.ts |
| 63 | // to allow for data protocol. |
nothing calls this directly
no test coverage detected
searching dependent graphs…