(
store: Store<IStoreState>,
config: DashConfig
)
| 51 | * @param config Dash configuration |
| 52 | */ |
| 53 | export async function initializeWebSocket( |
| 54 | store: Store<IStoreState>, |
| 55 | config: DashConfig |
| 56 | ): Promise<void> { |
| 57 | // Initialize WebSocket if: |
| 58 | // 1. Global websocket is enabled, OR |
| 59 | // 2. WebSocket config is available (for per-callback websocket=True) |
| 60 | const wsAvailable = !!( |
| 61 | config.websocket?.url && config.websocket?.worker_url |
| 62 | ); |
| 63 | if (!wsAvailable) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | // Check if SharedWorker is supported |
| 68 | if (typeof SharedWorker === 'undefined') { |
| 69 | console.warn( |
| 70 | 'SharedWorker not supported in this browser. ' + |
| 71 | 'WebSocket callbacks will fall back to HTTP.' |
| 72 | ); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | const workerClient = getWorkerClient(); |
| 77 | |
| 78 | // Helper to process a single set_props payload |
| 79 | const processSetProps = (payload: SetPropsPayload) => { |
| 80 | const {componentId, props: rawProps} = payload; |
| 81 | const parsedId = parseComponentId(componentId); |
| 82 | const state = store.getState(); |
| 83 | const componentPath = getPath(state.paths, parsedId); |
| 84 | |
| 85 | if (!componentPath) { |
| 86 | console.warn( |
| 87 | `SET_PROPS: Component ${componentId} not found in layout` |
| 88 | ); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | // Get old component for Patch processing and path recomputation |
| 93 | const oldComponent = path(componentPath, state.layout) as Record< |
| 94 | string, |
| 95 | unknown |
| 96 | > | null; |
| 97 | const oldProps = (oldComponent?.props || {}) as Record<string, unknown>; |
| 98 | |
| 99 | // Process props to handle Patch objects |
| 100 | const processedProps = parsePatchProps(rawProps, oldProps); |
| 101 | |
| 102 | // Update the component props |
| 103 | store.dispatch( |
| 104 | updateProps({ |
| 105 | props: processedProps, |
| 106 | itempath: componentPath, |
| 107 | renderType: 'websocket' |
| 108 | }) as any |
| 109 | ); |
| 110 |
no test coverage detected
searching dependent graphs…