repos / starfx

supercharged async flow control library.
git clone https://github.com/neurosnap/starfx.git

commit
addefe4
parent
f19888b
author
Eric Bower
date
2024-10-02 14:13:42 +0000 UTC
chore: cleanup thunk registry fix
2 files changed,  +10, -14
M deno.lock
+2, -2
 1@@ -4,7 +4,7 @@
 2     "https://crux.land/api/get/2KNRVU": "https://crux.land/api/get/2KNRVU.ts",
 3     "https://crux.land/api/get/router@0.0.5": "https://crux.land/api/get/2KNRVU",
 4     "https://crux.land/router@0.0.5": "https://crux.land/api/get/router@0.0.5",
 5-    "https://esm.sh/v135/@types/react@~18.2/index.d.ts": "https://esm.sh/v135/@types/react@18.2.38/index.d.ts"
 6+    "https://esm.sh/v128/@types/react@~18.2/index.d.ts": "https://esm.sh/v128/@types/react@18.2.38/index.d.ts"
 7   },
 8   "remote": {
 9     "https://crux.land/api/get/2KNRVU.ts": "6a77d55844aba78d01520c5ff0b2f0af7f24cc1716a0de8b3bb6bd918c47b5ba",
10@@ -68,7 +68,7 @@
11     "https://deno.land/x/mock_fetch@0.3.0/mod.ts": "7e7806c65ab17b2b684c334c4e565812bdaf504a3e9c938d2bb52bb67428bc89",
12     "https://esm.sh/immer@10.0.2?pin=v122": "7ac87b9c76176de8384a67f8cd93d44f75be1a7496c92707252acb669595c393",
13     "https://esm.sh/react-redux@8.0.5?pin=v122": "fa98e94dc8803fb84bee9eb08a13f11833f634d381003247207682823887dc51",
14-    "https://esm.sh/react@18.2.0?pin=v122": "04ad7dc6d11fa27b24c136686a334ecdd19e972fae627cd98cbdc13cdac238c2",
15+    "https://esm.sh/react@18.2.0?pin=v122": "8950a34a030620fce8349d6bd3913b3bdb186c5ec7968fa5ba4d054e22d78e6c",
16     "https://esm.sh/reselect@4.1.8?pin=v122": "486407fec8db8f0c87ba540ff6457dbec3c8ec8fa93a4845383bc8cdb33c6008",
17     "https://esm.sh/stable/react@18.2.0/denonext/react.mjs": "3c4f23bcfc53b256fcfaf6f834fa9f584c3bb7be667b2682c6cb6ba8ef88f8e6",
18     "https://esm.sh/v122/@babel/runtime@7.22.5/denonext/helpers/esm/extends.js": "3955a0ef35db01cd4efff831a9027924f90fa7d55621cd2b6b8519283e573c21",
M query/thunk.ts
+8, -12
 1@@ -1,6 +1,6 @@
 2 import { ActionContext, API_ACTION_PREFIX, takeEvery } from "../action.ts";
 3 import { compose } from "../compose.ts";
 4-import { Callable, Ok, Operation, Signal, spawn } from "../deps.ts";
 5+import { Callable, Ok, Operation, Signal } from "../deps.ts";
 6 import { keepAlive, supervise } from "../fx/mod.ts";
 7 import { createKey } from "./create-key.ts";
 8 import { isFn, isObject } from "./util.ts";
 9@@ -131,11 +131,10 @@ export function createThunks<Ctx extends ThunkCtx = ThunkCtx<any>>(
10   const actionMap: {
11     [key: string]: CreateActionWithPayload<Ctx, any>;
12   } = {};
13-
14   const thunkId = `${Date.now().toString(36)}-${
15     Math.random().toString(36).substring(2, 11)
16   }`;
17-  const thunkRegistry: Record<string, boolean> = { [thunkId]: false };
18+  let hasRegistered = false;
19 
20   function* defaultMiddleware(_: Ctx, next: Next) {
21     yield* next();
22@@ -254,24 +253,21 @@ export function createThunks<Ctx extends ThunkCtx = ThunkCtx<any>>(
23   }
24 
25   function* register() {
26-    if (thunkRegistry?.[thunkId] === true) {
27+    if (hasRegistered) {
28       console.warn("This thunk instance is already registered.");
29       return;
30     }
31-    thunkRegistry[thunkId] = true;
32+    hasRegistered = true;
33     signal = yield* ActionContext;
34 
35     // Register any thunks created after signal is available
36     yield* keepAlive(Object.values(visors));
37 
38     // Spawn a watcher for further thunk matchingPairs
39-    const task = yield* spawn(function* () {
40-      yield* takeEvery(
41-        `${API_ACTION_PREFIX}REGISTER_THUNK_${thunkId}`,
42-        watcher as any,
43-      );
44-    });
45-    yield* task;
46+    yield* takeEvery(
47+      `${API_ACTION_PREFIX}REGISTER_THUNK_${thunkId}`,
48+      watcher as any,
49+    );
50   }
51 
52   function routes() {