mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
convert terminal from epic to saga
This commit is contained in:
committed by
David Lechner
parent
314904605c
commit
e09fd8713f
+1
-2
@@ -5,10 +5,9 @@ import { Epic, combineEpics } from 'redux-observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import ble from './ble';
|
||||
import hub from './hub';
|
||||
import terminal from './terminal';
|
||||
|
||||
const rootEpic: Epic = (action$, store$, dependencies) =>
|
||||
combineEpics(ble, hub, terminal)(action$, store$, dependencies).pipe(
|
||||
combineEpics(ble, hub)(action$, store$, dependencies).pipe(
|
||||
catchError((error, source) => {
|
||||
console.error(error);
|
||||
return source;
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020 The Pybricks Authors
|
||||
|
||||
import { AnyAction } from 'redux';
|
||||
import { Epic, combineEpics, ofType } from 'redux-observable';
|
||||
import { Subject } from 'rxjs';
|
||||
import { ignoreElements, map, tap } from 'rxjs/operators';
|
||||
import { write } from '../actions/ble';
|
||||
import { TerminalDataAction, TerminalDataActionType } from '../actions/terminal';
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
const terminalOutputSubject = new Subject<string>();
|
||||
export const terminalOutput = terminalOutputSubject.asObservable();
|
||||
|
||||
// When terminal has focus this receives the input. All input is sent over BLE connection.
|
||||
const receiveTerminalData: Epic = (action$) =>
|
||||
action$.pipe(
|
||||
ofType<AnyAction, TerminalDataAction>(TerminalDataActionType.ReceivedData),
|
||||
map((a) => write(encoder.encode(a.value))),
|
||||
);
|
||||
|
||||
// Request to write to the terminal are handled by an observable rather than
|
||||
// using redux state.
|
||||
const sendTerminalData: Epic = (action$) =>
|
||||
action$.pipe(
|
||||
ofType<AnyAction, TerminalDataAction>(TerminalDataActionType.SendData),
|
||||
tap((a) => terminalOutputSubject.next(a.value)),
|
||||
ignoreElements(),
|
||||
);
|
||||
|
||||
export default combineEpics(receiveTerminalData, sendTerminalData);
|
||||
Reference in New Issue
Block a user