rask-ui 0.26.1 → 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.
- package/dist/compiler.d.ts +4 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +7 -0
- package/dist/component.d.ts.map +1 -1
- package/dist/component.js +9 -4
- package/dist/createAsync.d.ts +39 -0
- package/dist/createAsync.d.ts.map +1 -0
- package/dist/createAsync.js +47 -0
- package/dist/createComputed.d.ts +4 -0
- package/dist/createComputed.d.ts.map +1 -0
- package/dist/createComputed.js +69 -0
- package/dist/createEffect.d.ts +2 -0
- package/dist/createEffect.d.ts.map +1 -0
- package/dist/createEffect.js +29 -0
- package/dist/createMutation.d.ts +43 -0
- package/dist/createMutation.d.ts.map +1 -0
- package/dist/createMutation.js +76 -0
- package/dist/createQuery.d.ts +42 -0
- package/dist/createQuery.d.ts.map +1 -0
- package/dist/createQuery.js +80 -0
- package/dist/createRouter.d.ts +8 -0
- package/dist/createRouter.d.ts.map +1 -0
- package/dist/createRouter.js +27 -0
- package/dist/createState.d.ts +28 -0
- package/dist/createState.d.ts.map +1 -0
- package/dist/createState.js +129 -0
- package/dist/createTask.d.ts +31 -0
- package/dist/createTask.d.ts.map +1 -0
- package/dist/createTask.js +79 -0
- package/dist/createView.d.ts +28 -0
- package/dist/createView.d.ts.map +1 -0
- package/dist/createView.js +77 -0
- package/dist/error.d.ts +5 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/jsx.d.ts +11 -0
- package/dist/patchInferno.d.ts +6 -0
- package/dist/patchInferno.d.ts.map +1 -0
- package/dist/patchInferno.js +53 -0
- package/dist/scheduler.d.ts +4 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +107 -0
- package/dist/tests/batch.test.d.ts +2 -0
- package/dist/tests/batch.test.d.ts.map +1 -0
- package/dist/tests/batch.test.js +244 -0
- package/dist/tests/createComputed.test.d.ts +2 -0
- package/dist/tests/createComputed.test.d.ts.map +1 -0
- package/dist/tests/createComputed.test.js +257 -0
- package/dist/tests/createContext.test.d.ts +2 -0
- package/dist/tests/createContext.test.d.ts.map +1 -0
- package/dist/tests/createContext.test.js +136 -0
- package/dist/tests/createEffect.test.d.ts +2 -0
- package/dist/tests/createEffect.test.d.ts.map +1 -0
- package/dist/tests/createEffect.test.js +467 -0
- package/dist/tests/createState.test.d.ts +2 -0
- package/dist/tests/createState.test.d.ts.map +1 -0
- package/dist/tests/createState.test.js +144 -0
- package/dist/tests/createTask.test.d.ts +2 -0
- package/dist/tests/createTask.test.d.ts.map +1 -0
- package/dist/tests/createTask.test.js +322 -0
- package/dist/tests/createView.test.d.ts +2 -0
- package/dist/tests/createView.test.d.ts.map +1 -0
- package/dist/tests/createView.test.js +203 -0
- package/dist/tests/error.test.d.ts +2 -0
- package/dist/tests/error.test.d.ts.map +1 -0
- package/dist/tests/error.test.js +168 -0
- package/dist/tests/observation.test.d.ts +2 -0
- package/dist/tests/observation.test.d.ts.map +1 -0
- package/dist/tests/observation.test.js +341 -0
- package/dist/transformer.d.ts.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useComputed.d.ts +5 -0
- package/dist/useComputed.d.ts.map +1 -0
- package/dist/useComputed.js +69 -0
- package/dist/useLookup.d.ts +2 -0
- package/dist/useLookup.d.ts.map +1 -0
- package/dist/useLookup.js +22 -0
- package/dist/useQuery.d.ts +25 -0
- package/dist/useQuery.d.ts.map +1 -0
- package/dist/useQuery.js +25 -0
- package/dist/useSuspendAsync.d.ts +18 -0
- package/dist/useSuspendAsync.d.ts.map +1 -0
- package/dist/useSuspendAsync.js +37 -0
- package/dist/useTask.d.ts +25 -0
- package/dist/useTask.d.ts.map +1 -0
- package/dist/useTask.js +70 -0
- package/package.json +1 -1
- package/swc-plugin/target/wasm32-wasip1/release/swc_plugin_rask_component.wasm +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type QueryState<T, I = null> = {
|
|
2
|
+
isPending: true;
|
|
3
|
+
error: null;
|
|
4
|
+
value: I;
|
|
5
|
+
} | {
|
|
6
|
+
isPending: false;
|
|
7
|
+
error: null;
|
|
8
|
+
value: T;
|
|
9
|
+
} | {
|
|
10
|
+
isPending: false;
|
|
11
|
+
error: string;
|
|
12
|
+
value: I | null;
|
|
13
|
+
};
|
|
14
|
+
export type Query<T, P, I = null> = [
|
|
15
|
+
QueryState<T, I>,
|
|
16
|
+
[
|
|
17
|
+
P
|
|
18
|
+
] extends [never] ? (params: P) => void : () => void
|
|
19
|
+
];
|
|
20
|
+
export declare function useQuery<T>(query: () => Promise<T>): Query<T, never>;
|
|
21
|
+
export declare function useQuery<T>(query: () => Promise<T>, initialValue: T): Query<T, never, T>;
|
|
22
|
+
export declare function useQuery<T, P>(query: (params: P) => Promise<T>): Query<T, never>;
|
|
23
|
+
export declare function useQuery<T, P>(query: (params: P) => Promise<T>, initialValue: T): Query<T, never, T>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=useQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../src/useQuery.ts"],"names":[],"mappings":"AAGA,KAAK,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,IACvB;IACE,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC;CACV,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC;CACV,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CACjB,CAAC;AAEN,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,IAAI;IAClC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;IAChB;QAAC,CAAC;KAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;CACvD,CAAC;AAEF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACtE,wBAAgB,QAAQ,CAAC,CAAC,EACxB,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACvB,YAAY,EAAE,CAAC,GACd,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AACtB,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC/B,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACnB,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAChC,YAAY,EAAE,CAAC,GACd,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC"}
|
package/dist/useQuery.js
ADDED
|
@@ -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"}
|
package/dist/useTask.js
ADDED
|
@@ -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
|
Binary file
|