@vladimirdev635/gql-client-vue 0.0.110 → 0.0.112
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/useOperation.d.ts +2 -2
- package/{useOperation.jsx → useOperation.js} +4 -8
- package/useSubscription.d.ts +2 -2
- package/{useSubscription.jsx → useSubscription.js} +4 -8
- /package/tests/{useOperation.spec.jsx → useOperation.spec.js} +0 -0
- /package/tests/{useSubscription.spec.jsx → useSubscription.spec.js} +0 -0
package/package.json
CHANGED
package/useOperation.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeRefOrGetter, ShallowRef } from 'vue';
|
|
2
2
|
import type { ExecuteResult, IExecutor, OperationResult, OperationVariables, RequestContext, SyncOperation } from './types.js';
|
|
3
3
|
export interface OperationLoadingState {
|
|
4
4
|
state: 'loading';
|
|
@@ -12,4 +12,4 @@ export interface OperationFailureState {
|
|
|
12
12
|
}
|
|
13
13
|
export type OperationState<TResult> = OperationLoadingState | OperationSuccessState<TResult> | OperationFailureState;
|
|
14
14
|
export type UseOperationHookReturnType<TResult> = ShallowRef<OperationState<TResult>>;
|
|
15
|
-
export declare function useOperation<TExecutor extends IExecutor<TRequestContext>, TRequestContext extends RequestContext, TOperation extends SyncOperation<unknown, unknown>>(executor: TExecutor, operation: TOperation, variables:
|
|
15
|
+
export declare function useOperation<TExecutor extends IExecutor<TRequestContext>, TRequestContext extends RequestContext, TOperation extends SyncOperation<unknown, unknown>>(executor: TExecutor, operation: TOperation, variables: MaybeRefOrGetter<OperationVariables<TOperation>>, requestContext: MaybeRefOrGetter<TRequestContext>): UseOperationHookReturnType<OperationResult<TOperation>>;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onUnmounted, shallowRef, toValue, watch, } from 'vue';
|
|
2
2
|
import { loadingState } from './loading-state.js';
|
|
3
3
|
export function useOperation(executor, operation, variables, requestContext) {
|
|
4
4
|
const state = shallowRef(loadingState);
|
|
5
|
-
watch([
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
() => (isRef(variables) ? variables.value : variables),
|
|
9
|
-
() => isRef(requestContext) ? requestContext.value : requestContext,
|
|
10
|
-
], ([exec, op, vars, ctx]) => {
|
|
11
|
-
exec.executeSync(op, vars, ctx)
|
|
5
|
+
watch([() => toValue(variables), () => toValue(requestContext)], ([vars, ctx]) => {
|
|
6
|
+
executor
|
|
7
|
+
.executeSync(operation, vars, ctx)
|
|
12
8
|
.then((result) => {
|
|
13
9
|
state.value = { state: 'success', ...result };
|
|
14
10
|
})
|
package/useSubscription.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeRefOrGetter, type ShallowRef } from 'vue';
|
|
2
2
|
import type { IExecutor, OperationResult, OperationVariables, RequestContext, SubOpAsyncIterable, SubscriptionOperation } from './types.js';
|
|
3
3
|
import { type OperationState } from './useOperation.js';
|
|
4
4
|
export type UseSubscriptionHookReturnType<TResult> = ShallowRef<OperationState<SubOpAsyncIterable<TResult>>>;
|
|
5
|
-
export declare function useSubscription<TExecutor extends IExecutor<TRequestContext>, TRequestContext extends RequestContext, TOperation extends SubscriptionOperation<unknown, unknown>>(executor: TExecutor, operation: TOperation, variables:
|
|
5
|
+
export declare function useSubscription<TExecutor extends IExecutor<TRequestContext>, TRequestContext extends RequestContext, TOperation extends SubscriptionOperation<unknown, unknown>>(executor: TExecutor, operation: TOperation, variables: MaybeRefOrGetter<OperationVariables<TOperation>>, requestContext: MaybeRefOrGetter<TRequestContext>): UseSubscriptionHookReturnType<OperationResult<TOperation>>;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onUnmounted, shallowRef, toValue, watch, } from 'vue';
|
|
2
2
|
import { loadingState } from './loading-state.js';
|
|
3
3
|
export function useSubscription(executor, operation, variables, requestContext) {
|
|
4
4
|
const state = shallowRef(loadingState);
|
|
5
|
-
watch([
|
|
6
|
-
() => executor,
|
|
7
|
-
() => operation,
|
|
8
|
-
() => (isRef(variables) ? variables.value : variables),
|
|
9
|
-
() => isRef(requestContext) ? requestContext.value : requestContext,
|
|
10
|
-
], ([exec, op, vars, ctx], _oldValues, onCleanup) => {
|
|
5
|
+
watch([() => toValue(variables), () => toValue(requestContext)], ([vars, ctx], _, onCleanup) => {
|
|
11
6
|
const controller = new AbortController();
|
|
12
7
|
onCleanup(() => {
|
|
13
8
|
if (state.value.state === 'success') {
|
|
@@ -18,7 +13,8 @@ export function useSubscription(executor, operation, variables, requestContext)
|
|
|
18
13
|
}
|
|
19
14
|
state.value = loadingState;
|
|
20
15
|
});
|
|
21
|
-
|
|
16
|
+
executor
|
|
17
|
+
.executeSubscription(operation, vars, ctx, controller)
|
|
22
18
|
.then((result) => {
|
|
23
19
|
if (controller.signal.aborted)
|
|
24
20
|
return;
|
|
File without changes
|
|
File without changes
|