Skip to content

Commit

Permalink
fix: remove widgets update sub
Browse files Browse the repository at this point in the history
(fixes widgets not updating after scheme start)
  • Loading branch information
nvsukhanov committed Mar 26, 2024
1 parent d0e955e commit dcd968a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import { Observable } from 'rxjs';
import { Observable, takeUntil } from 'rxjs';
import { Store } from '@ngrx/store';
import { Actions, ofType } from '@ngrx/effects';

import { CONTROL_SCHEME_WIDGETS_DATA_ACTIONS } from '../../../actions';
import { CONTROL_SCHEME_ACTIONS, CONTROL_SCHEME_WIDGETS_DATA_ACTIONS } from '../../../actions';
import { ControlSchemeModel } from '../../../models';
import { IWidgetsReadTasksFactory } from './i-widgets-read-tasks-factory';

export function createWidgetReadTasks(
scheme: ControlSchemeModel,
store: Store,
widgetTaskFactory: IWidgetsReadTasksFactory,
actions: Actions
): Array<Observable<unknown>> {
const result: Array<Observable<unknown>> = [];
const readerTasks = widgetTaskFactory.createReadTasks(scheme.widgets);
for (const task of readerTasks) {
const obs = new Observable((subscriber) => {
let initialValueReceived = false;
const sub = task.subscribe((taskData) => {
task.pipe(
takeUntil(actions.pipe(
ofType(
CONTROL_SCHEME_ACTIONS.stopScheme,
CONTROL_SCHEME_ACTIONS.schemeStartFailed
)
))
).subscribe((taskData) => {
if (!initialValueReceived) {
initialValueReceived = true;
subscriber.next(null);
subscriber.complete();
}
store.dispatch(CONTROL_SCHEME_WIDGETS_DATA_ACTIONS.updateWidgetData(taskData));
});
return () => {
sub.unsubscribe();
};
});

result.push(obs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const PRE_RUN_SCHEME_EFFECT = createEffect((
...createPreRunMotorPositionQueryTasks(scheme, hubStorage, store),
...createPreRunSetAccelerationProfileTasks(scheme, hubStorage),
...createPreRunSetDecelerationProfileTasks(scheme, hubStorage),
...createWidgetReadTasks(scheme, store, widgetReadTaskFactory)
...createWidgetReadTasks(scheme, store, widgetReadTaskFactory, actions)
]),
timeout(appConfig.schemeStartStopTimeoutMs),
map(() => CONTROL_SCHEME_ACTIONS.schemeStarted({ name: scheme.name })),
Expand Down

0 comments on commit dcd968a

Please sign in to comment.