mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-07-28 04:08:05 +00:00
add test for editor saga
This commit is contained in:
committed by
David Lechner
parent
31c3e2b52e
commit
5c3ec89e3b
+10
-2
@@ -3,21 +3,25 @@
|
||||
|
||||
import { END, MulticastChannel, Saga, Task, runSaga, stdChannel } from 'redux-saga';
|
||||
import { Action } from '../src/actions';
|
||||
import { RootState } from '../src/reducers';
|
||||
|
||||
export class AsyncSaga {
|
||||
private channel: MulticastChannel<Action>;
|
||||
private dispatches: (Action | END)[];
|
||||
private takers: { put: (action: Action | END) => void }[];
|
||||
private channel: MulticastChannel<Action>;
|
||||
private state: Partial<RootState>;
|
||||
private task: Task;
|
||||
|
||||
public constructor(saga: Saga) {
|
||||
this.channel = stdChannel();
|
||||
this.dispatches = [];
|
||||
this.takers = [];
|
||||
this.channel = stdChannel();
|
||||
this.state = {};
|
||||
this.task = runSaga(
|
||||
{
|
||||
channel: this.channel,
|
||||
dispatch: this.dispatch.bind(this),
|
||||
getState: () => this.state,
|
||||
onError: (e) => fail(e),
|
||||
},
|
||||
saga,
|
||||
@@ -56,6 +60,10 @@ export class AsyncSaga {
|
||||
return Promise.resolve(next);
|
||||
}
|
||||
|
||||
public setState(state: Partial<RootState>): void {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public async end(): Promise<void> {
|
||||
this.task.cancel();
|
||||
await this.task.toPromise();
|
||||
|
||||
Reference in New Issue
Block a user