milkio 1.0.0-alpha.10 → 1.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/use/index.ts +15 -9
package/package.json
CHANGED
package/use/index.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
let use: any | undefined;
|
|
1
|
+
import { $context } from "../context";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
return use;
|
|
9
|
-
};
|
|
3
|
+
export const defineUse = <Mode extends "dynamic" | "static", Use extends Mode extends "static" ? () => Promise<unknown> | unknown : (...args: [$context, ...Array<unknown>]) => Promise<unknown> | unknown>(mode: Mode, use: Use): ((...args: Parameters<Use>) => Promise<Awaited<ReturnType<Use>>>) => {
|
|
4
|
+
if (mode === "static") {
|
|
5
|
+
let useCreated: any | undefined;
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
const getUse = async () => {
|
|
8
|
+
if (useCreated === undefined) {
|
|
9
|
+
useCreated = await (use as any)();
|
|
10
|
+
}
|
|
11
|
+
return useCreated;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return getUse;
|
|
15
|
+
} else {
|
|
16
|
+
return use as any;
|
|
17
|
+
}
|
|
12
18
|
};
|