Skip to content

Commit

Permalink
added individual runner info record set action
Browse files Browse the repository at this point in the history
  • Loading branch information
fde31 committed Jun 15, 2024
1 parent 774da95 commit d09e603
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
25 changes: 23 additions & 2 deletions src/actions/appStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export enum StatusActionType {
SET_STATUS = "SET_STATUS",
SET_ENDPOINT = "SET_ENDPOINT",
SET_SHOW_ENDPOINT_INFO = "SET_SHOW_ENDPOINT_INFO",
INIT_RUNNER_INFO = "INIT_RUNNER_INFO"
INIT_RUNNER_INFO = "INIT_RUNNER_INFO",
SET_RUNNER_INFO_VALUE = "SET_RUNNER_INFO_VALUE"
}

export interface ISetAppStatus extends ActionBase {
Expand Down Expand Up @@ -41,8 +42,15 @@ export interface IInitRunnerInfo extends ActionBase {
};
}

export interface ISetRunnerInfoValue extends ActionBase {
type: StatusActionType.SET_RUNNER_INFO_VALUE;
payload: {
record: RunnerInfoRecord;
};
}


export type StatusAction = ISetAppStatus | ISetEndpoint | ISetShowEndpointInfo | IInitRunnerInfo;
export type StatusAction = ISetAppStatus | ISetEndpoint | ISetShowEndpointInfo | IInitRunnerInfo | ISetRunnerInfoValue

export const setAppStatus = (status: AppStatus, error?: Error): StatusAction => {
return {
Expand Down Expand Up @@ -106,3 +114,16 @@ export const initRunnerInfo = (desc: OSCQueryRNBOState): StatusAction => {
}
};
};

export const setRunnerInfoValue = (key: RunnerInfoKey, value: RunnerInfoRecord["oscValue"]): AppThunk =>
(dispatch, getState) => {
const state = getState();
const record = state.appStatus.runnerInfo.get(key);
if (!record) return;
dispatch({
type: StatusActionType.SET_RUNNER_INFO_VALUE,
payload: {
record: record.setValue(value)
}
});
};
8 changes: 6 additions & 2 deletions src/models/runnerInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum RunnerInfoKey {
XRunCount = "xrun_count"
}

export type JackInfoRecordProps = {
export type RunnerInfoRecordProps = {
id: RunnerInfoKey;
description: string;
oscValue: number | string | boolean | null;
Expand All @@ -16,7 +16,7 @@ export type JackInfoRecordProps = {

type RunnierInfoOSCDescType = OSCQueryStringValue | OSCQueryIntValue | OSCQueryBooleanValue | OSCQueryFloatValue;

export class RunnerInfoRecord extends ImmuRecord<JackInfoRecordProps>({
export class RunnerInfoRecord extends ImmuRecord<RunnerInfoRecordProps>({
id: RunnerInfoKey.CPULoad,
description: "",
oscValue: 0,
Expand All @@ -25,6 +25,10 @@ export class RunnerInfoRecord extends ImmuRecord<JackInfoRecordProps>({

}) {

public setValue(value: RunnerInfoRecordProps["oscValue"]): RunnerInfoRecord {
return this.set("oscValue", value);
}

public static fromDescription(id: RunnerInfoKey, desc: RunnierInfoOSCDescType): RunnerInfoRecord {
return new RunnerInfoRecord({
id,
Expand Down
8 changes: 8 additions & 0 deletions src/reducers/appStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export const appStatus = (state: AppStatusState = {
};
}

case StatusActionType.SET_RUNNER_INFO_VALUE : {
const { record } = action.payload;
return {
...state,
runnerInfo: state.runnerInfo.set(record.id, record)
};
}

default:
return state;
}
Expand Down

0 comments on commit d09e603

Please sign in to comment.