mirror of
https://github.com/tiqi-group/pydase.git
synced 2026-01-21 19:32:24 +01:00
updates frontend reducer to accept new sio_callback event data
This commit is contained in:
@@ -18,12 +18,11 @@ type Action =
|
|||||||
| { type: 'SET_DATA'; data: State }
|
| { type: 'SET_DATA'; data: State }
|
||||||
| {
|
| {
|
||||||
type: 'UPDATE_ATTRIBUTE';
|
type: 'UPDATE_ATTRIBUTE';
|
||||||
parentPath: string;
|
fullAccessPath: string;
|
||||||
name: string;
|
newValue: SerializedValue;
|
||||||
value: SerializedValue;
|
|
||||||
};
|
};
|
||||||
type UpdateMessage = {
|
type UpdateMessage = {
|
||||||
data: { parent_path: string; name: string; value: SerializedValue };
|
data: { full_access_path: string; value: SerializedValue };
|
||||||
};
|
};
|
||||||
type LogMessage = {
|
type LogMessage = {
|
||||||
levelname: LevelName;
|
levelname: LevelName;
|
||||||
@@ -35,10 +34,7 @@ const reducer = (state: State, action: Action): State => {
|
|||||||
case 'SET_DATA':
|
case 'SET_DATA':
|
||||||
return action.data;
|
return action.data;
|
||||||
case 'UPDATE_ATTRIBUTE': {
|
case 'UPDATE_ATTRIBUTE': {
|
||||||
const pathList = action.parentPath.split('.').slice(1).concat(action.name);
|
return setNestedValueByPath(state, action.fullAccessPath, action.newValue);
|
||||||
const joinedPath = pathList.join('.');
|
|
||||||
|
|
||||||
return setNestedValueByPath(state, joinedPath, action.value);
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error();
|
throw new Error();
|
||||||
@@ -129,14 +125,13 @@ const App = () => {
|
|||||||
|
|
||||||
function onNotify(value: UpdateMessage) {
|
function onNotify(value: UpdateMessage) {
|
||||||
// Extracting data from the notification
|
// Extracting data from the notification
|
||||||
const { parent_path: parentPath, name, value: newValue } = value.data;
|
const { full_access_path: fullAccessPath, value: newValue } = value.data;
|
||||||
|
|
||||||
// Dispatching the update to the reducer
|
// Dispatching the update to the reducer
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'UPDATE_ATTRIBUTE',
|
type: 'UPDATE_ATTRIBUTE',
|
||||||
parentPath,
|
fullAccessPath,
|
||||||
name,
|
newValue
|
||||||
value: newValue
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
|
|
||||||
// Whether to show the name infront of the component (false if used with a slider)
|
// Whether to show the name infront of the component (false if used with a slider)
|
||||||
const showName = props.showName !== undefined ? props.showName : true;
|
const showName = props.showName !== undefined ? props.showName : true;
|
||||||
// If emitUpdate is passed, use this instead of the emit_update from the socket
|
// If emitUpdate is passed, use this instead of the setAttribute from the socket
|
||||||
// Also used when used with a slider
|
// Also used when used with a slider
|
||||||
const emitUpdate =
|
const emitUpdate =
|
||||||
props.customEmitUpdate !== undefined ? props.customEmitUpdate : setAttribute;
|
props.customEmitUpdate !== undefined ? props.customEmitUpdate : setAttribute;
|
||||||
|
|||||||
Reference in New Issue
Block a user