repos / starfx

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

commit
56f96ae
parent
14f1594
author
Eric Bower
date
2024-08-16 18:21:08 +0000 UTC
chore(thunk): use `console.warn` instead of `console.error`
2 files changed,  +10, -10
M query/thunk.ts
+7, -7
 1@@ -161,6 +161,12 @@ export function createThunks<Ctx extends ThunkCtx = ThunkCtx<any>>(
 2   }
 3 
 4   function create(name: string, ...args: any[]) {
 5+    if (Object.hasOwn(visors, name)) {
 6+      const msg =
 7+        `[${name}] already exists, do you have two thunks with the same name?`;
 8+      console.warn(msg);
 9+    }
10+
11     const type = createType(name);
12     const action = (payload?: any) => {
13       return { type, payload };
14@@ -192,12 +198,6 @@ export function createThunks<Ctx extends ThunkCtx = ThunkCtx<any>>(
15       throw new Error("Middleware must be a function");
16     }
17 
18-    if (middlewareMap[name]) {
19-      console.warn(
20-        `[${name}] already exists which means you have two functions with the same name`,
21-      );
22-    }
23-
24     middlewareMap[name] = fn || defaultMiddleware;
25 
26     const tt = req ? (req as any).supervisor : supervisor;
27@@ -217,7 +217,7 @@ export function createThunks<Ctx extends ThunkCtx = ThunkCtx<any>>(
28 
29     const actionFn = (options?: Ctx["payload"]) => {
30       if (!signal) {
31-        console.error(errMsg);
32+        console.warn(errMsg);
33       }
34       const key = createKey(name, options);
35       return action({ name, key, options });
M test/thunk.test.ts
+3, -3
 1@@ -521,9 +521,9 @@ it(tests, "should be able to create thunk after `register()`", () => {
 2 });
 3 
 4 it(tests, "should warn when calling thunk before registered", () => {
 5-  const err = console.error;
 6+  const err = console.warn;
 7   let called = false;
 8-  console.error = () => {
 9+  console.warn = () => {
10     called = true;
11   };
12   const api = createThunks<RoboCtx>();
13@@ -533,5 +533,5 @@ it(tests, "should warn when calling thunk before registered", () => {
14   const action = api.create("/users");
15   store.dispatch(action());
16   asserts.assertEquals(called, true);
17-  console.error = err;
18+  console.warn = err;
19 });