- commit
- 8b15e81
- parent
- 5b3374e
- author
- Eric Bower
- date
- 2023-09-16 03:20:06 +0000 UTC
chore: modify supervisor types
2 files changed,
+12,
-15
+2,
-0
1@@ -93,6 +93,7 @@ export function* takeLatest<T>(
2 }
3 });
4 }
5+export const latest = takeLatest;
6
7 export function* takeLeading<T>(
8 pattern: ActionPattern,
9@@ -106,6 +107,7 @@ export function* takeLeading<T>(
10 }
11 });
12 }
13+export const leading = takeLeading;
14
15 export function* put(action: AnyAction | AnyAction[]) {
16 const store = yield* StoreContext;
+10,
-15
1@@ -1,22 +1,17 @@
2 import { call, race } from "../fx/mod.ts";
3-import { take, takeLatest, takeLeading } from "./fx.ts";
4+import { take } from "./fx.ts";
5 import { Operation, sleep, spawn, Task } from "../deps.ts";
6-import type { ActionWPayload, AnyAction, OpFn } from "../types.ts";
7-import type { CreateActionPayload } from "../query/mod.ts";
8+import type { ActionWPayload, AnyAction } from "../types.ts";
9+import type { CreateActionPayload, Supervisor } from "../query/mod.ts";
10
11 const MS = 1000;
12 const SECONDS = 1 * MS;
13 const MINUTES = 60 * SECONDS;
14
15-export function* latest(action: string, saga: any) {
16- yield takeLatest(`${action}`, saga);
17-}
18-
19-export function* leading(action: string, saga: any) {
20- yield takeLeading(`${action}`, saga);
21-}
22-
23-export function poll(parentTimer: number = 5 * 1000, cancelType?: string) {
24+export function poll(
25+ parentTimer: number = 5 * 1000,
26+ cancelType?: string,
27+): Supervisor {
28 return function* poller<T>(
29 actionType: string,
30 op: (action: AnyAction) => Operation<T>,
31@@ -49,10 +44,10 @@ export function poll(parentTimer: number = 5 * 1000, cancelType?: string) {
32 * So if we call `fetchApp({ id: 1 })` and then `fetchApp({ id: 2 })` if we use a normal
33 * cache timer then the second call will not send an http request.
34 */
35-export function timer(timer: number = 5 * MINUTES) {
36- return function* onTimer(
37+export function timer(timer: number = 5 * MINUTES): Supervisor {
38+ return function* onTimer<T>(
39 actionType: string,
40- op: (action: AnyAction) => OpFn,
41+ op: (action: AnyAction) => Operation<T>,
42 ) {
43 const map: { [key: string]: Task<unknown> } = {};
44