The API requests that Dash's front-end makes should be configurable. In order to make them configurable, we will need to do the following things:
- We will need to make the Dash Front-end (
dash-renderer) a standalone library that can be initialized and invoked from other libraries
- We will need to extend the
dash-renderer to take a set of config input parameters
- Some of these input parameters will be functions or promises that we will call before certain actions
- For this issue, we will start by a
request_pre and request_post parameter that will be called before and after HTTP requests with the entire request and response objects. This will enable the developer to transform the data before and after network requests.
Example:
dash_renderer({
request_pre: requestPayload => {
return modifyRequest(requestPayload);
},
request_post: (requestPayload, responsePayload) => {
return modifyResponse(requestPayload, responsePayload)
}
})
So, the hooks are only the network requests. In the code, this would fit in here:
|
return fetch(`${urlBase(config)}_dash-update-component`, { |
|
method: 'POST', |
|
headers: { |
|
'Content-Type': 'application/json', |
|
'X-CSRFToken': cookie.parse(document.cookie)._csrf_token |
|
}, |
|
credentials: 'same-origin', |
|
body: JSON.stringify(payload) |
|
}).then(function handleResponse(res) { |
Note that in order for users to supply their own arguments, I believe they would need to provide their own instance of dash_renderer by overriding the index file (as discussed here: plotly/dash#265)
The API requests that Dash's front-end makes should be configurable. In order to make them configurable, we will need to do the following things:
dash-renderer) a standalone library that can be initialized and invoked from other librariesdash-rendererto take a set of config input parametersrequest_preandrequest_postparameter that will be called before and after HTTP requests with the entire request and response objects. This will enable the developer to transform the data before and after network requests.Example:
So, the hooks are only the network requests. In the code, this would fit in here:
dash-renderer/src/actions/index.js
Lines 447 to 455 in 70bb93e
Note that in order for users to supply their own arguments, I believe they would need to provide their own instance of
dash_rendererby overriding the index file (as discussed here: plotly/dash#265)