rask-ui 0.27.0 → 0.28.0

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.
Files changed (86) hide show
  1. package/dist/compiler.d.ts +4 -0
  2. package/dist/compiler.d.ts.map +1 -0
  3. package/dist/compiler.js +7 -0
  4. package/dist/component.d.ts.map +1 -1
  5. package/dist/component.js +9 -4
  6. package/dist/createAsync.d.ts +39 -0
  7. package/dist/createAsync.d.ts.map +1 -0
  8. package/dist/createAsync.js +47 -0
  9. package/dist/createComputed.d.ts +4 -0
  10. package/dist/createComputed.d.ts.map +1 -0
  11. package/dist/createComputed.js +69 -0
  12. package/dist/createEffect.d.ts +2 -0
  13. package/dist/createEffect.d.ts.map +1 -0
  14. package/dist/createEffect.js +29 -0
  15. package/dist/createMutation.d.ts +43 -0
  16. package/dist/createMutation.d.ts.map +1 -0
  17. package/dist/createMutation.js +76 -0
  18. package/dist/createQuery.d.ts +42 -0
  19. package/dist/createQuery.d.ts.map +1 -0
  20. package/dist/createQuery.js +80 -0
  21. package/dist/createRouter.d.ts +8 -0
  22. package/dist/createRouter.d.ts.map +1 -0
  23. package/dist/createRouter.js +27 -0
  24. package/dist/createState.d.ts +28 -0
  25. package/dist/createState.d.ts.map +1 -0
  26. package/dist/createState.js +129 -0
  27. package/dist/createTask.d.ts +31 -0
  28. package/dist/createTask.d.ts.map +1 -0
  29. package/dist/createTask.js +79 -0
  30. package/dist/createView.d.ts +28 -0
  31. package/dist/createView.d.ts.map +1 -0
  32. package/dist/createView.js +77 -0
  33. package/dist/error.d.ts +5 -0
  34. package/dist/error.d.ts.map +1 -0
  35. package/dist/error.js +16 -0
  36. package/dist/jsx.d.ts +11 -0
  37. package/dist/patchInferno.d.ts +6 -0
  38. package/dist/patchInferno.d.ts.map +1 -0
  39. package/dist/patchInferno.js +53 -0
  40. package/dist/scheduler.d.ts +4 -0
  41. package/dist/scheduler.d.ts.map +1 -0
  42. package/dist/scheduler.js +107 -0
  43. package/dist/tests/batch.test.d.ts +2 -0
  44. package/dist/tests/batch.test.d.ts.map +1 -0
  45. package/dist/tests/batch.test.js +244 -0
  46. package/dist/tests/createComputed.test.d.ts +2 -0
  47. package/dist/tests/createComputed.test.d.ts.map +1 -0
  48. package/dist/tests/createComputed.test.js +257 -0
  49. package/dist/tests/createContext.test.d.ts +2 -0
  50. package/dist/tests/createContext.test.d.ts.map +1 -0
  51. package/dist/tests/createContext.test.js +136 -0
  52. package/dist/tests/createEffect.test.d.ts +2 -0
  53. package/dist/tests/createEffect.test.d.ts.map +1 -0
  54. package/dist/tests/createEffect.test.js +467 -0
  55. package/dist/tests/createState.test.d.ts +2 -0
  56. package/dist/tests/createState.test.d.ts.map +1 -0
  57. package/dist/tests/createState.test.js +144 -0
  58. package/dist/tests/createTask.test.d.ts +2 -0
  59. package/dist/tests/createTask.test.d.ts.map +1 -0
  60. package/dist/tests/createTask.test.js +322 -0
  61. package/dist/tests/createView.test.d.ts +2 -0
  62. package/dist/tests/createView.test.d.ts.map +1 -0
  63. package/dist/tests/createView.test.js +203 -0
  64. package/dist/tests/error.test.d.ts +2 -0
  65. package/dist/tests/error.test.d.ts.map +1 -0
  66. package/dist/tests/error.test.js +168 -0
  67. package/dist/tests/observation.test.d.ts +2 -0
  68. package/dist/tests/observation.test.d.ts.map +1 -0
  69. package/dist/tests/observation.test.js +341 -0
  70. package/dist/transformer.d.ts.map +1 -1
  71. package/dist/types.d.ts +6 -1
  72. package/dist/types.d.ts.map +1 -1
  73. package/dist/useComputed.d.ts +5 -0
  74. package/dist/useComputed.d.ts.map +1 -0
  75. package/dist/useComputed.js +69 -0
  76. package/dist/useQuery.d.ts +25 -0
  77. package/dist/useQuery.d.ts.map +1 -0
  78. package/dist/useQuery.js +25 -0
  79. package/dist/useSuspendAsync.d.ts +18 -0
  80. package/dist/useSuspendAsync.d.ts.map +1 -0
  81. package/dist/useSuspendAsync.js +37 -0
  82. package/dist/useTask.d.ts +25 -0
  83. package/dist/useTask.d.ts.map +1 -0
  84. package/dist/useTask.js +70 -0
  85. package/package.json +1 -1
  86. package/swc-plugin/target/wasm32-wasip1/release/swc_plugin_rask_component.wasm +0 -0
@@ -0,0 +1,25 @@
1
+ import { useEffect } from "./useEffect";
2
+ import { useTask } from "./useTask";
3
+ export function useQuery(query, initialValue) {
4
+ const [taskState, runTask] = useTask(query);
5
+ let lastValue = initialValue === undefined ? null : initialValue;
6
+ useEffect(() => {
7
+ if (taskState.result) {
8
+ lastValue = taskState.result;
9
+ }
10
+ });
11
+ return [
12
+ {
13
+ get value() {
14
+ return taskState.result || lastValue;
15
+ },
16
+ get isPending() {
17
+ return taskState.isPending;
18
+ },
19
+ get error() {
20
+ return taskState.error;
21
+ },
22
+ },
23
+ runTask,
24
+ ];
25
+ }
@@ -0,0 +1,18 @@
1
+ import { AsyncState } from "./useAsync";
2
+ type SuspendAsyncState<T extends Record<string, AsyncState<any>>> = {
3
+ values: {
4
+ [K in keyof T]: T[K]["value"];
5
+ };
6
+ } & ({
7
+ isPending: true;
8
+ error: null;
9
+ } | {
10
+ isPending: false;
11
+ error: string;
12
+ } | {
13
+ isPending: false;
14
+ error: null;
15
+ });
16
+ export declare function useSuspendAsync<T extends Record<string, AsyncState<any>>>(asyncs: T): SuspendAsyncState<T>;
17
+ export {};
18
+ //# sourceMappingURL=useSuspendAsync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSuspendAsync.d.ts","sourceRoot":"","sources":["../src/useSuspendAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAIxC,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI;IAClE,MAAM,EAAE;SACL,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;KAC9B,CAAC;CACH,GAAG,CACA;IACE,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;CACb,CACJ,CAAC;AAEF,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,EACvE,MAAM,EAAE,CAAC,wBAyCV"}
@@ -0,0 +1,37 @@
1
+ import { useEffect } from "./useEffect";
2
+ import { useState } from "./useState";
3
+ export function useSuspendAsync(asyncs) {
4
+ const state = useState({
5
+ isPending: false,
6
+ error: null,
7
+ values: Object.keys(asyncs).reduce((aggr, key) => ({ ...aggr, [key]: asyncs[key].value }), {}),
8
+ });
9
+ useEffect(() => {
10
+ let isPending = false;
11
+ let error = "";
12
+ for (const key in asyncs) {
13
+ if (asyncs[key].error) {
14
+ error += asyncs[key].error + "\n";
15
+ continue;
16
+ }
17
+ if (asyncs[key].isPending) {
18
+ isPending = true;
19
+ continue;
20
+ }
21
+ }
22
+ if (error) {
23
+ state.isPending = false;
24
+ state.error = error;
25
+ return;
26
+ }
27
+ if (isPending) {
28
+ state.isPending = false;
29
+ state.error = null;
30
+ return;
31
+ }
32
+ for (const key in asyncs) {
33
+ state.values[key] = asyncs[key].value;
34
+ }
35
+ });
36
+ return state;
37
+ }
@@ -0,0 +1,25 @@
1
+ export type TaskState<P, T> = {
2
+ isPending: false;
3
+ params: null;
4
+ result: null;
5
+ error: null;
6
+ } | {
7
+ isPending: true;
8
+ result: T | null;
9
+ params: P;
10
+ error: null;
11
+ } | {
12
+ isPending: false;
13
+ params: null;
14
+ result: T;
15
+ error: null;
16
+ } | {
17
+ isPending: false;
18
+ params: null;
19
+ result: null;
20
+ error: string;
21
+ };
22
+ export type Task<A, B = never> = [B] extends [never] ? [TaskState<null, A>, () => void] : [TaskState<A, B>, (params: A) => void];
23
+ export declare function useTask<T>(task: (params: undefined, signal: AbortSignal) => Promise<T>): Task<T>;
24
+ export declare function useTask<P, T>(task: (params: P, signal: AbortSignal) => Promise<T>): Task<P, T>;
25
+ //# sourceMappingURL=useTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTask.d.ts","sourceRoot":"","sources":["../src/useTask.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,IACtB;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IACjB,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,MAAM,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAChD,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,GAChC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC;AAE3C,wBAAgB,OAAO,CAAC,CAAC,EACvB,IAAI,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3D,IAAI,CAAC,CAAC,CAAC,CAAC;AACX,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAC1B,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GACnD,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { useCleanup, getCurrentComponent } from "./component";
2
+ import { assignState, useState } from "./useState";
3
+ export function useTask(task) {
4
+ const currentComponent = getCurrentComponent();
5
+ if (!currentComponent || currentComponent.isRendering) {
6
+ throw new Error("Only use createTask in component setup");
7
+ }
8
+ const state = useState({
9
+ isPending: false,
10
+ result: null,
11
+ error: null,
12
+ params: null,
13
+ });
14
+ let currentAbortController;
15
+ const fetch = (params) => {
16
+ currentAbortController?.abort();
17
+ const abortController = (currentAbortController = new AbortController());
18
+ const promise = task(params, abortController.signal);
19
+ promise
20
+ .then((result) => {
21
+ if (abortController.signal.aborted) {
22
+ return;
23
+ }
24
+ assignState(state, {
25
+ isPending: false,
26
+ result,
27
+ error: null,
28
+ params: null,
29
+ });
30
+ })
31
+ .catch((error) => {
32
+ if (abortController.signal.aborted) {
33
+ return;
34
+ }
35
+ assignState(state, {
36
+ isPending: false,
37
+ result: null,
38
+ error: String(error),
39
+ params: null,
40
+ });
41
+ });
42
+ return promise;
43
+ };
44
+ useCleanup(() => currentAbortController?.abort());
45
+ return [
46
+ {
47
+ get isPending() {
48
+ return state.isPending;
49
+ },
50
+ get result() {
51
+ return state.result;
52
+ },
53
+ get error() {
54
+ return state.error;
55
+ },
56
+ get params() {
57
+ return state.params;
58
+ },
59
+ },
60
+ (params) => {
61
+ fetch(params);
62
+ assignState(state, {
63
+ isPending: true,
64
+ result: null,
65
+ error: null,
66
+ params: (params || null),
67
+ });
68
+ },
69
+ ];
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rask-ui",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",