@data-client/vue 0.0.1 → 0.0.3

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 (48) hide show
  1. package/README.md +22 -24
  2. package/dist/index.js +112 -6
  3. package/dist/index.umd.min.js +1 -1
  4. package/lib/consumers/index.d.ts +4 -1
  5. package/lib/consumers/index.d.ts.map +1 -1
  6. package/lib/consumers/index.js +5 -2
  7. package/lib/consumers/useDebounce.d.ts +16 -0
  8. package/lib/consumers/useDebounce.d.ts.map +1 -0
  9. package/lib/consumers/useDebounce.js +50 -0
  10. package/lib/consumers/useLive.d.ts +13 -0
  11. package/lib/consumers/useLive.d.ts.map +1 -0
  12. package/lib/consumers/useLive.js +17 -0
  13. package/lib/consumers/useLoading.d.ts +18 -0
  14. package/lib/consumers/useLoading.d.ts.map +1 -0
  15. package/lib/consumers/useLoading.js +44 -0
  16. package/lib/consumers/useQuery.js +3 -3
  17. package/lib/consumers/useSubscription.js +3 -3
  18. package/lib/consumers/useSuspense.js +3 -3
  19. package/lib/context.d.ts +1 -1
  20. package/lib/context.d.ts.map +1 -1
  21. package/lib/context.js +2 -2
  22. package/package.json +1 -6
  23. package/src/__tests__/useDebounce.web.ts +264 -0
  24. package/src/__tests__/useLive.web.ts +162 -0
  25. package/src/__tests__/useLoading.web.ts +238 -0
  26. package/src/consumers/index.ts +4 -4
  27. package/src/consumers/useDebounce.ts +78 -0
  28. package/src/consumers/useLive.ts +64 -0
  29. package/src/consumers/useLoading.ts +47 -0
  30. package/src/consumers/useQuery.ts +2 -2
  31. package/src/consumers/useSubscription.ts +2 -2
  32. package/src/consumers/useSuspense.ts +2 -2
  33. package/src/context.ts +1 -1
  34. package/ts3.4/consumers/index.d.ts +4 -1
  35. package/ts3.4/consumers/useDebounce.d.ts +19 -0
  36. package/ts3.4/consumers/useLive.d.ts +19 -0
  37. package/ts3.4/consumers/useLoading.d.ts +22 -0
  38. package/ts3.4/context.d.ts +1 -1
  39. package/lib/components/DataProvider.d.ts +0 -11
  40. package/lib/components/DataProvider.d.ts.map +0 -1
  41. package/lib/components/DataProvider.js +0 -18
  42. package/lib/consumers/useInjects.d.ts +0 -5
  43. package/lib/consumers/useInjects.d.ts.map +0 -1
  44. package/lib/consumers/useInjects.js +0 -8
  45. package/src/components/DataProvider.ts +0 -26
  46. package/src/consumers/useInjects.ts +0 -12
  47. package/ts3.4/components/DataProvider.d.ts +0 -11
  48. package/ts3.4/consumers/useInjects.d.ts +0 -5
@@ -0,0 +1,238 @@
1
+ import { mount } from '@vue/test-utils';
2
+ import { defineComponent, h, nextTick } from 'vue';
3
+
4
+ import useLoading from '../consumers/useLoading';
5
+
6
+ describe('vue useLoading()', () => {
7
+ async function flushUntil(
8
+ wrapper: any,
9
+ predicate: () => boolean,
10
+ tries = 100,
11
+ ) {
12
+ for (let i = 0; i < tries; i++) {
13
+ if (predicate()) return;
14
+ await Promise.resolve();
15
+ await nextTick();
16
+ await new Promise(resolve => setTimeout(resolve, 0));
17
+ }
18
+ }
19
+
20
+ it('tracks loading state for async functions', async () => {
21
+ let resolvePromise: (value: string) => void;
22
+ const mockAsyncFunction = jest.fn(
23
+ () =>
24
+ new Promise<string>(resolve => {
25
+ resolvePromise = resolve;
26
+ }),
27
+ );
28
+
29
+ const TestComponent = defineComponent({
30
+ name: 'TestComponent',
31
+ setup() {
32
+ const [wrappedFunction, loading, error] = useLoading(mockAsyncFunction);
33
+
34
+ const handleClick = async () => {
35
+ await wrappedFunction();
36
+ };
37
+
38
+ return () =>
39
+ h('div', [
40
+ h(
41
+ 'button',
42
+ {
43
+ onClick: handleClick,
44
+ 'data-testid': 'test-button',
45
+ },
46
+ loading.value ? 'Loading...' : 'Click me',
47
+ ),
48
+ h('div', { 'data-testid': 'error' }, error.value?.message || ''),
49
+ h('div', { 'data-testid': 'loading' }, loading.value.toString()),
50
+ ]);
51
+ },
52
+ });
53
+
54
+ const wrapper = mount(TestComponent);
55
+
56
+ // Initially not loading
57
+ expect(wrapper.find('[data-testid="loading"]').text()).toBe('false');
58
+ expect(wrapper.find('[data-testid="test-button"]').text()).toBe('Click me');
59
+
60
+ // Click to trigger loading
61
+ await wrapper.find('[data-testid="test-button"]').trigger('click');
62
+ await nextTick();
63
+
64
+ // Should be loading
65
+ expect(wrapper.find('[data-testid="loading"]').text()).toBe('true');
66
+ expect(wrapper.find('[data-testid="test-button"]').text()).toBe(
67
+ 'Loading...',
68
+ );
69
+
70
+ // Resolve the promise
71
+ resolvePromise!('success');
72
+ await flushUntil(
73
+ wrapper,
74
+ () => wrapper.find('[data-testid="loading"]').text() === 'false',
75
+ );
76
+
77
+ // Should not be loading anymore
78
+ expect(wrapper.find('[data-testid="loading"]').text()).toBe('false');
79
+ expect(wrapper.find('[data-testid="test-button"]').text()).toBe('Click me');
80
+ expect(mockAsyncFunction).toHaveBeenCalledTimes(1);
81
+ });
82
+
83
+ it('handles errors from async functions', async () => {
84
+ const testError = new Error('Test error');
85
+ const mockAsyncFunction = jest.fn(() => Promise.reject(testError));
86
+
87
+ const TestComponent = defineComponent({
88
+ name: 'TestComponent',
89
+ setup() {
90
+ const [wrappedFunction, loading, error] = useLoading(mockAsyncFunction);
91
+
92
+ const handleClick = async () => {
93
+ await wrappedFunction();
94
+ };
95
+
96
+ return () =>
97
+ h('div', [
98
+ h(
99
+ 'button',
100
+ {
101
+ onClick: handleClick,
102
+ 'data-testid': 'test-button',
103
+ },
104
+ 'Click me',
105
+ ),
106
+ h('div', { 'data-testid': 'error' }, error.value?.message || ''),
107
+ h('div', { 'data-testid': 'loading' }, loading.value.toString()),
108
+ ]);
109
+ },
110
+ });
111
+
112
+ const wrapper = mount(TestComponent);
113
+
114
+ // Click to trigger error
115
+ await wrapper.find('[data-testid="test-button"]').trigger('click');
116
+ await flushUntil(
117
+ wrapper,
118
+ () => wrapper.find('[data-testid="error"]').text() === 'Test error',
119
+ );
120
+
121
+ // Should capture the error
122
+ expect(wrapper.find('[data-testid="error"]').text()).toBe('Test error');
123
+ expect(wrapper.find('[data-testid="loading"]').text()).toBe('false');
124
+ expect(mockAsyncFunction).toHaveBeenCalledTimes(1);
125
+ });
126
+
127
+ it('does not update loading state after component unmount', async () => {
128
+ let resolvePromise: (value: string) => void;
129
+ const mockAsyncFunction = jest.fn(
130
+ () =>
131
+ new Promise<string>(resolve => {
132
+ resolvePromise = resolve;
133
+ }),
134
+ );
135
+
136
+ const TestComponent = defineComponent({
137
+ name: 'TestComponent',
138
+ setup() {
139
+ const [wrappedFunction, loading] = useLoading(mockAsyncFunction);
140
+
141
+ const handleClick = async () => {
142
+ await wrappedFunction();
143
+ };
144
+
145
+ return () =>
146
+ h('div', [
147
+ h(
148
+ 'button',
149
+ {
150
+ onClick: handleClick,
151
+ 'data-testid': 'test-button',
152
+ },
153
+ 'Click me',
154
+ ),
155
+ h('div', { 'data-testid': 'loading' }, loading.value.toString()),
156
+ ]);
157
+ },
158
+ });
159
+
160
+ const wrapper = mount(TestComponent);
161
+
162
+ // Click to trigger loading
163
+ await wrapper.find('[data-testid="test-button"]').trigger('click');
164
+ await nextTick();
165
+
166
+ // Should be loading
167
+ expect(wrapper.find('[data-testid="loading"]').text()).toBe('true');
168
+
169
+ // Unmount component before resolving
170
+ wrapper.unmount();
171
+
172
+ // Resolve the promise after unmount
173
+ resolvePromise!('success');
174
+ await new Promise(resolve => setTimeout(resolve, 0));
175
+
176
+ // Component should be unmounted, no errors should occur
177
+ expect(mockAsyncFunction).toHaveBeenCalledTimes(1);
178
+ });
179
+
180
+ it('clears error on subsequent calls', async () => {
181
+ const testError = new Error('Test error');
182
+ let shouldError = true;
183
+ const mockAsyncFunction = jest.fn(() => {
184
+ if (shouldError) {
185
+ return Promise.reject(testError);
186
+ }
187
+ return Promise.resolve('success');
188
+ });
189
+
190
+ const TestComponent = defineComponent({
191
+ name: 'TestComponent',
192
+ setup() {
193
+ const [wrappedFunction, loading, error] = useLoading(mockAsyncFunction);
194
+
195
+ const handleClick = async () => {
196
+ await wrappedFunction();
197
+ };
198
+
199
+ return () =>
200
+ h('div', [
201
+ h(
202
+ 'button',
203
+ {
204
+ onClick: handleClick,
205
+ 'data-testid': 'test-button',
206
+ },
207
+ 'Click me',
208
+ ),
209
+ h('div', { 'data-testid': 'error' }, error.value?.message || ''),
210
+ h('div', { 'data-testid': 'loading' }, loading.value.toString()),
211
+ ]);
212
+ },
213
+ });
214
+
215
+ const wrapper = mount(TestComponent);
216
+
217
+ // First call - should error
218
+ await wrapper.find('[data-testid="test-button"]').trigger('click');
219
+ await flushUntil(
220
+ wrapper,
221
+ () => wrapper.find('[data-testid="error"]').text() === 'Test error',
222
+ );
223
+
224
+ expect(wrapper.find('[data-testid="error"]').text()).toBe('Test error');
225
+
226
+ // Second call - should succeed and clear error
227
+ shouldError = false;
228
+ await wrapper.find('[data-testid="test-button"]').trigger('click');
229
+ await flushUntil(
230
+ wrapper,
231
+ () => wrapper.find('[data-testid="error"]').text() === '',
232
+ );
233
+
234
+ expect(wrapper.find('[data-testid="error"]').text()).toBe('');
235
+ expect(wrapper.find('[data-testid="loading"]').text()).toBe('false');
236
+ expect(mockAsyncFunction).toHaveBeenCalledTimes(2);
237
+ });
238
+ });
@@ -1,7 +1,7 @@
1
1
  export { default as useSuspense } from './useSuspense.js';
2
2
  export { default as useSubscription } from './useSubscription.js';
3
3
  export { default as useQuery } from './useQuery.js';
4
- export {
5
- injectController as useController,
6
- injectState as useStateRef,
7
- } from '../context.js';
4
+ export { default as useLive } from './useLive.js';
5
+ export { default as useLoading } from './useLoading.js';
6
+ export { default as useDebounce } from './useDebounce.js';
7
+ export { useController as useController } from '../context.js';
@@ -0,0 +1,78 @@
1
+ import { ref, watch, onUnmounted, type Ref } from 'vue';
2
+
3
+ /**
4
+ * Keeps value updated after delay time
5
+ *
6
+ * @see https://dataclient.io/docs/api/useDebounce
7
+ * @param value Any immutable value (can be a ref)
8
+ * @param delay Time in milliseconds to wait til updating the value
9
+ * @param updatable Whether to update at all
10
+ * @example
11
+ ```
12
+ const [debouncedQuery, isPending] = useDebounce(query, 200);
13
+ const list = useSuspense(getThings, { query: debouncedQuery.value });
14
+ ```
15
+ */
16
+ export default function useDebounce<T>(
17
+ value: T | Ref<T>,
18
+ delay: number,
19
+ updatable: boolean | Ref<boolean> = true,
20
+ ): [Ref<T>, Ref<boolean>] {
21
+ const debouncedValue = ref(
22
+ typeof value === 'object' && value !== null && 'value' in value ?
23
+ value.value
24
+ : value,
25
+ ) as Ref<T>;
26
+ const isPending = ref(false);
27
+ let timeoutId: ReturnType<typeof setTimeout> | null = null;
28
+
29
+ const clearExistingTimeout = () => {
30
+ if (timeoutId !== null) {
31
+ clearTimeout(timeoutId);
32
+ timeoutId = null;
33
+ }
34
+ };
35
+
36
+ // Watch the input value and debounce updates
37
+ watch(
38
+ [
39
+ () =>
40
+ typeof value === 'object' && value !== null && 'value' in value ?
41
+ value.value
42
+ : value,
43
+ () =>
44
+ (
45
+ typeof updatable === 'object' &&
46
+ updatable !== null &&
47
+ 'value' in updatable
48
+ ) ?
49
+ updatable.value
50
+ : updatable,
51
+ () => delay,
52
+ ],
53
+ ([newValue, isUpdatable]) => {
54
+ clearExistingTimeout();
55
+
56
+ if (!isUpdatable) {
57
+ isPending.value = false;
58
+ return;
59
+ }
60
+
61
+ isPending.value = true;
62
+
63
+ timeoutId = setTimeout(() => {
64
+ debouncedValue.value = newValue;
65
+ isPending.value = false;
66
+ timeoutId = null;
67
+ }, delay);
68
+ },
69
+ { immediate: false },
70
+ );
71
+
72
+ // Cleanup on unmount
73
+ onUnmounted(() => {
74
+ clearExistingTimeout();
75
+ });
76
+
77
+ return [debouncedValue, isPending];
78
+ }
@@ -0,0 +1,64 @@
1
+ import type {
2
+ EndpointInterface,
3
+ Denormalize,
4
+ Schema,
5
+ FetchFunction,
6
+ ResolveType,
7
+ DenormalizeNullable,
8
+ } from '@data-client/core';
9
+ import type { DeepReadonly, ComputedRef } from 'vue';
10
+
11
+ import useSubscription from './useSubscription.js';
12
+ import useSuspense from './useSuspense.js';
13
+
14
+ /**
15
+ * Ensure an endpoint is available. Keeps it fresh once it is.
16
+ *
17
+ * useSuspense() + useSubscription()
18
+ * @see https://dataclient.io/docs/api/useLive
19
+ * @throws {Promise} If data is not yet available.
20
+ * @throws {NetworkError} If fetch fails.
21
+ */
22
+ export default function useLive<
23
+ E extends EndpointInterface<
24
+ FetchFunction,
25
+ Schema | undefined,
26
+ undefined | false
27
+ >,
28
+ >(
29
+ endpoint: E,
30
+ ...args: readonly [...Parameters<E>]
31
+ ): Promise<
32
+ DeepReadonly<
33
+ ComputedRef<
34
+ E['schema'] extends undefined | null ? ResolveType<E>
35
+ : Denormalize<E['schema']>
36
+ >
37
+ >
38
+ >;
39
+
40
+ export default function useLive<
41
+ E extends EndpointInterface<
42
+ FetchFunction,
43
+ Schema | undefined,
44
+ undefined | false
45
+ >,
46
+ >(
47
+ endpoint: E,
48
+ ...args: readonly [...Parameters<E>] | readonly [null]
49
+ ): Promise<
50
+ DeepReadonly<
51
+ ComputedRef<
52
+ E['schema'] extends undefined | null ? ResolveType<E> | undefined
53
+ : DenormalizeNullable<E['schema']>
54
+ >
55
+ >
56
+ >;
57
+
58
+ export default async function useLive(
59
+ endpoint: any,
60
+ ...args: any[]
61
+ ): Promise<any> {
62
+ useSubscription(endpoint, ...args);
63
+ return useSuspense(endpoint, ...args);
64
+ }
@@ -0,0 +1,47 @@
1
+ import { ref, onUnmounted, type Ref } from 'vue';
2
+
3
+ /**
4
+ * Takes an async function and tracks resolution as a boolean.
5
+ *
6
+ * @see https://dataclient.io/docs/api/useLoading
7
+ * @param func A function returning a promise
8
+ * @example
9
+ ```
10
+ function Button({ onClick, children, ...props }) {
11
+ const [clickHandler, loading] = useLoading(onClick);
12
+ return h('button', { onClick: clickHandler, ...props },
13
+ loading.value ? 'Loading...' : children
14
+ );
15
+ }
16
+ ```
17
+ */
18
+ export default function useLoading<F extends (...args: any) => Promise<any>>(
19
+ func: F,
20
+ ): [F, Ref<boolean>, Ref<Error | undefined>] {
21
+ const loading = ref(false);
22
+ const error = ref<undefined | Error>(undefined);
23
+ const isMounted = ref(true);
24
+
25
+ onUnmounted(() => {
26
+ isMounted.value = false;
27
+ });
28
+
29
+ // Create the wrapped function directly - no need for computed in Vue
30
+ const wrappedFunc = (async (...args: any) => {
31
+ loading.value = true;
32
+ error.value = undefined;
33
+ let ret;
34
+ try {
35
+ ret = await func(...args);
36
+ } catch (e: any) {
37
+ error.value = e;
38
+ } finally {
39
+ if (isMounted.value) {
40
+ loading.value = false;
41
+ }
42
+ }
43
+ return ret;
44
+ }) as F;
45
+
46
+ return [wrappedFunc, loading, error];
47
+ }
@@ -6,7 +6,7 @@ import type {
6
6
  } from '@data-client/core';
7
7
  import { computed, watch, type ComputedRef } from 'vue';
8
8
 
9
- import { injectController, injectState } from '../context.js';
9
+ import { useController, injectState } from '../context.js';
10
10
 
11
11
  /**
12
12
  * Query the store (non-suspense).
@@ -21,7 +21,7 @@ export default function useQuery<S extends Queryable>(
21
21
  ...args: NI<SchemaArgs<S>>
22
22
  ): ComputedRef<DenormalizeNullable<S> | undefined> {
23
23
  const stateRef = injectState();
24
- const controller = injectController();
24
+ const controller = useController();
25
25
 
26
26
  // Compute query meta based on state and args. This mirrors React's memoization
27
27
  // that keys off state.entities/indexes and args.
@@ -5,7 +5,7 @@ import type {
5
5
  } from '@data-client/core';
6
6
  import { computed, unref, watch } from 'vue';
7
7
 
8
- import { injectController } from '../context.js';
8
+ import { useController } from '../context.js';
9
9
 
10
10
  /**
11
11
  * Keeps a resource fresh by subscribing to updates.
@@ -19,7 +19,7 @@ export default function useSubscription<
19
19
  undefined | false
20
20
  >,
21
21
  >(endpoint: E, ...args: readonly [...Parameters<E>] | readonly [null]) {
22
- const controller = injectController();
22
+ const controller = useController();
23
23
 
24
24
  // Track top-level reactive args (Refs are unwrapped). This allows props/refs to trigger resubscribe.
25
25
  const resolvedArgs = computed(() => args.map(a => unref(a as any)) as any);
@@ -15,7 +15,7 @@ import {
15
15
  type ComputedRef,
16
16
  } from 'vue';
17
17
 
18
- import { injectController, injectState } from '../context.js';
18
+ import { useController, injectState } from '../context.js';
19
19
 
20
20
  export default function useSuspense<
21
21
  E extends EndpointInterface<
@@ -58,7 +58,7 @@ export default async function useSuspense(
58
58
  ...args: any[]
59
59
  ): Promise<any> {
60
60
  const stateRef = injectState();
61
- const controller = injectController();
61
+ const controller = useController();
62
62
 
63
63
  const key = args[0] !== null ? endpoint.key(...args) : '';
64
64
  const responseMeta = computed(() =>
package/src/context.ts CHANGED
@@ -13,7 +13,7 @@ export const ControllerKey: InjectionKey<Controller> = Symbol(
13
13
  export const FallbackStateRef: ShallowRef<State<unknown>> =
14
14
  shallowRef(initialState);
15
15
 
16
- export function injectController(): Controller {
16
+ export function useController(): Controller {
17
17
  const ctrl = inject(ControllerKey, null);
18
18
  if (!ctrl) {
19
19
  if (process.env.NODE_ENV !== 'production') {
@@ -1,5 +1,8 @@
1
1
  export { default as useSuspense } from './useSuspense.js';
2
2
  export { default as useSubscription } from './useSubscription.js';
3
3
  export { default as useQuery } from './useQuery.js';
4
- export { injectController as useController, injectState as useStateRef, } from '../context.js';
4
+ export { default as useLive } from './useLive.js';
5
+ export { default as useLoading } from './useLoading.js';
6
+ export { default as useDebounce } from './useDebounce.js';
7
+ export { useController as useController } from '../context.js';
5
8
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { Ref } from 'vue';
2
+ /**
3
+ * Keeps value updated after delay time
4
+ *
5
+ * @see https://dataclient.io/docs/api/useDebounce
6
+ * @param value Any immutable value (can be a ref)
7
+ * @param delay Time in milliseconds to wait til updating the value
8
+ * @param updatable Whether to update at all
9
+ * @example
10
+ ```
11
+ const [debouncedQuery, isPending] = useDebounce(query, 200);
12
+ const list = useSuspense(getThings, { query: debouncedQuery.value });
13
+ ```
14
+ */
15
+ export default function useDebounce<T>(value: T | Ref<T>, delay: number, updatable?: boolean | Ref<boolean>): [
16
+ Ref<T>,
17
+ Ref<boolean>
18
+ ];
19
+ //# sourceMappingURL=useDebounce.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { EndpointInterface, Denormalize, Schema, FetchFunction, ResolveType, DenormalizeNullable } from '@data-client/core';
2
+ import { DeepReadonly, ComputedRef } from 'vue';
3
+ /**
4
+ * Ensure an endpoint is available. Keeps it fresh once it is.
5
+ *
6
+ * useSuspense() + useSubscription()
7
+ * @see https://dataclient.io/docs/api/useLive
8
+ * @throws {Promise} If data is not yet available.
9
+ * @throws {NetworkError} If fetch fails.
10
+ */
11
+ export default function useLive<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
12
+ ...Parameters<E>
13
+ ]): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> : Denormalize<E['schema']>>>>;
14
+ export default function useLive<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
15
+ ...Parameters<E>
16
+ ] | readonly [
17
+ null
18
+ ]): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> | undefined : DenormalizeNullable<E['schema']>>>>;
19
+ //# sourceMappingURL=useLive.d.ts.map
@@ -0,0 +1,22 @@
1
+ import { Ref } from 'vue';
2
+ /**
3
+ * Takes an async function and tracks resolution as a boolean.
4
+ *
5
+ * @see https://dataclient.io/docs/api/useLoading
6
+ * @param func A function returning a promise
7
+ * @example
8
+ ```
9
+ function Button({ onClick, children, ...props }) {
10
+ const [clickHandler, loading] = useLoading(onClick);
11
+ return h('button', { onClick: clickHandler, ...props },
12
+ loading.value ? 'Loading...' : children
13
+ );
14
+ }
15
+ ```
16
+ */
17
+ export default function useLoading<F extends (...args: any) => Promise<any>>(func: F): [
18
+ F,
19
+ Ref<boolean>,
20
+ Ref<Error | undefined>
21
+ ];
22
+ //# sourceMappingURL=useLoading.d.ts.map
@@ -5,6 +5,6 @@ export declare const StateKey: InjectionKey<ShallowRef<State<unknown>>>;
5
5
  export declare const ControllerKey: InjectionKey<Controller>;
6
6
  /** Fallback state ref used when no provider is found. */
7
7
  export declare const FallbackStateRef: ShallowRef<State<unknown>>;
8
- export declare function injectController(): Controller;
8
+ export declare function useController(): Controller;
9
9
  export declare function injectState(): ShallowRef<State<unknown>>;
10
10
  //# sourceMappingURL=context.d.ts.map
@@ -1,11 +0,0 @@
1
- import { Controller as DataController } from '@data-client/core';
2
- import type { State, Manager, GCInterface } from '@data-client/core';
3
- export interface ProviderProps {
4
- managers?: Manager[];
5
- initialState?: State<unknown>;
6
- Controller?: typeof DataController;
7
- gcPolicy?: GCInterface;
8
- }
9
- declare const _default: import("vue").DefineComponent<ProviderProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ProviderProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
- export default _default;
11
- //# sourceMappingURL=DataProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DataProvider.d.ts","sourceRoot":"","sources":["../../src/components/DataProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKrE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,YAAY,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9B,UAAU,CAAC,EAAE,OAAO,cAAc,CAAC;IACnC,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB;;AAED,wBAYG"}
@@ -1,18 +0,0 @@
1
- import { defineComponent } from 'vue';
2
- import { provideDataClient } from '../providers/provideDataClient.js';
3
- export default defineComponent({
4
- name: 'DataProvider',
5
- props: ['managers', 'initialState', 'Controller', 'gcPolicy'],
6
- setup(props, {
7
- slots
8
- }) {
9
- provideDataClient({
10
- Controller: props.Controller,
11
- gcPolicy: props.gcPolicy,
12
- initialState: props.initialState,
13
- managers: props.managers
14
- });
15
- return () => slots.default ? slots.default() : null;
16
- }
17
- });
18
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJkZWZpbmVDb21wb25lbnQiLCJwcm92aWRlRGF0YUNsaWVudCIsIm5hbWUiLCJwcm9wcyIsInNldHVwIiwic2xvdHMiLCJDb250cm9sbGVyIiwiZ2NQb2xpY3kiLCJpbml0aWFsU3RhdGUiLCJtYW5hZ2VycyIsImRlZmF1bHQiXSwic291cmNlcyI6WyIuLi8uLi9zcmMvY29tcG9uZW50cy9EYXRhUHJvdmlkZXIudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgQ29udHJvbGxlciBhcyBEYXRhQ29udHJvbGxlciB9IGZyb20gJ0BkYXRhLWNsaWVudC9jb3JlJztcbmltcG9ydCB0eXBlIHsgU3RhdGUsIE1hbmFnZXIsIEdDSW50ZXJmYWNlIH0gZnJvbSAnQGRhdGEtY2xpZW50L2NvcmUnO1xuaW1wb3J0IHsgZGVmaW5lQ29tcG9uZW50IH0gZnJvbSAndnVlJztcblxuaW1wb3J0IHsgcHJvdmlkZURhdGFDbGllbnQgfSBmcm9tICcuLi9wcm92aWRlcnMvcHJvdmlkZURhdGFDbGllbnQuanMnO1xuXG5leHBvcnQgaW50ZXJmYWNlIFByb3ZpZGVyUHJvcHMge1xuICBtYW5hZ2Vycz86IE1hbmFnZXJbXTtcbiAgaW5pdGlhbFN0YXRlPzogU3RhdGU8dW5rbm93bj47XG4gIENvbnRyb2xsZXI/OiB0eXBlb2YgRGF0YUNvbnRyb2xsZXI7XG4gIGdjUG9saWN5PzogR0NJbnRlcmZhY2U7XG59XG5cbmV4cG9ydCBkZWZhdWx0IGRlZmluZUNvbXBvbmVudDxQcm92aWRlclByb3BzPih7XG4gIG5hbWU6ICdEYXRhUHJvdmlkZXInLFxuICBwcm9wczogWydtYW5hZ2VycycsICdpbml0aWFsU3RhdGUnLCAnQ29udHJvbGxlcicsICdnY1BvbGljeSddIGFzIGFueSxcbiAgc2V0dXAocHJvcHMsIHsgc2xvdHMgfSkge1xuICAgIHByb3ZpZGVEYXRhQ2xpZW50KHtcbiAgICAgIENvbnRyb2xsZXI6IHByb3BzLkNvbnRyb2xsZXIsXG4gICAgICBnY1BvbGljeTogcHJvcHMuZ2NQb2xpY3ksXG4gICAgICBpbml0aWFsU3RhdGU6IHByb3BzLmluaXRpYWxTdGF0ZSxcbiAgICAgIG1hbmFnZXJzOiBwcm9wcy5tYW5hZ2VycyxcbiAgICB9KTtcbiAgICByZXR1cm4gKCkgPT4gKHNsb3RzLmRlZmF1bHQgPyBzbG90cy5kZWZhdWx0KCkgOiBudWxsKTtcbiAgfSxcbn0pO1xuIl0sIm1hcHBpbmdzIjoiQUFFQSxTQUFTQSxlQUFlLFFBQVEsS0FBSztBQUVyQyxTQUFTQyxpQkFBaUIsUUFBUSxtQ0FBbUM7QUFTckUsZUFBZUQsZUFBZSxDQUFnQjtFQUM1Q0UsSUFBSSxFQUFFLGNBQWM7RUFDcEJDLEtBQUssRUFBRSxDQUFDLFVBQVUsRUFBRSxjQUFjLEVBQUUsWUFBWSxFQUFFLFVBQVUsQ0FBUTtFQUNwRUMsS0FBS0EsQ0FBQ0QsS0FBSyxFQUFFO0lBQUVFO0VBQU0sQ0FBQyxFQUFFO0lBQ3RCSixpQkFBaUIsQ0FBQztNQUNoQkssVUFBVSxFQUFFSCxLQUFLLENBQUNHLFVBQVU7TUFDNUJDLFFBQVEsRUFBRUosS0FBSyxDQUFDSSxRQUFRO01BQ3hCQyxZQUFZLEVBQUVMLEtBQUssQ0FBQ0ssWUFBWTtNQUNoQ0MsUUFBUSxFQUFFTixLQUFLLENBQUNNO0lBQ2xCLENBQUMsQ0FBQztJQUNGLE9BQU8sTUFBT0osS0FBSyxDQUFDSyxPQUFPLEdBQUdMLEtBQUssQ0FBQ0ssT0FBTyxDQUFDLENBQUMsR0FBRyxJQUFLO0VBQ3ZEO0FBQ0YsQ0FBQyxDQUFDIiwiaWdub3JlTGlzdCI6W119
@@ -1,5 +0,0 @@
1
- import type { State } from '@data-client/core';
2
- import type { ShallowRef } from 'vue';
3
- export declare function useController(): import("@data-client/core").Controller<import("@data-client/core").DataClientDispatch>;
4
- export declare function useStateRef(): ShallowRef<State<unknown>>;
5
- //# sourceMappingURL=useInjects.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useInjects.d.ts","sourceRoot":"","sources":["../../src/consumers/useInjects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAItC,wBAAgB,aAAa,2FAE5B;AAED,wBAAgB,WAAW,IAAI,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAExD"}
@@ -1,8 +0,0 @@
1
- import { injectController, injectState } from '../context.js';
2
- export function useController() {
3
- return injectController();
4
- }
5
- export function useStateRef() {
6
- return injectState();
7
- }
8
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJpbmplY3RDb250cm9sbGVyIiwiaW5qZWN0U3RhdGUiLCJ1c2VDb250cm9sbGVyIiwidXNlU3RhdGVSZWYiXSwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uc3VtZXJzL3VzZUluamVjdHMudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUgeyBTdGF0ZSB9IGZyb20gJ0BkYXRhLWNsaWVudC9jb3JlJztcbmltcG9ydCB0eXBlIHsgU2hhbGxvd1JlZiB9IGZyb20gJ3Z1ZSc7XG5cbmltcG9ydCB7IGluamVjdENvbnRyb2xsZXIsIGluamVjdFN0YXRlIH0gZnJvbSAnLi4vY29udGV4dC5qcyc7XG5cbmV4cG9ydCBmdW5jdGlvbiB1c2VDb250cm9sbGVyKCkge1xuICByZXR1cm4gaW5qZWN0Q29udHJvbGxlcigpO1xufVxuXG5leHBvcnQgZnVuY3Rpb24gdXNlU3RhdGVSZWYoKTogU2hhbGxvd1JlZjxTdGF0ZTx1bmtub3duPj4ge1xuICByZXR1cm4gaW5qZWN0U3RhdGUoKTtcbn1cbiJdLCJtYXBwaW5ncyI6IkFBR0EsU0FBU0EsZ0JBQWdCLEVBQUVDLFdBQVcsUUFBUSxlQUFlO0FBRTdELE9BQU8sU0FBU0MsYUFBYUEsQ0FBQSxFQUFHO0VBQzlCLE9BQU9GLGdCQUFnQixDQUFDLENBQUM7QUFDM0I7QUFFQSxPQUFPLFNBQVNHLFdBQVdBLENBQUEsRUFBK0I7RUFDeEQsT0FBT0YsV0FBVyxDQUFDLENBQUM7QUFDdEIiLCJpZ25vcmVMaXN0IjpbXX0=