@livequery/react 1.0.110 → 2.0.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.
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { Transporter } from '@livequery/types';
3
2
  export type LiveQueryContextOption = {
4
3
  transporter: Transporter;
@@ -1,2 +1,2 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
- export declare const createContextFromHook: <T, K>(fn: ((props: T) => K) | (() => K)) => [() => K, ({ children, ...props }: React.PropsWithChildren<T>) => React.JSX.Element];
2
+ export declare const createContextFromHook: <T, K>(fn: ((props: T) => K) | (() => K)) => [() => K, ({ children, ...props }: PropsWithChildren<T>) => React.JSX.Element];
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const createStaticContext: <T extends {}>() => [() => T, ({ children, ...props }: import("react").PropsWithChildren<{
3
2
  value: T;
4
3
  }>) => import("react").JSX.Element];
@@ -2,14 +2,14 @@ import { LivequeryBaseEntity, QueryOption } from "@livequery/types";
2
2
  import { CollectionObservable, CollectionOption, CollectionStream } from "@livequery/client";
3
3
  export type useCollectionDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = CollectionOption<T> & {
4
4
  lazy?: boolean;
5
- filters: Partial<QueryOption<T>>;
5
+ options: Partial<QueryOption<T>>;
6
6
  load_all: boolean;
7
7
  };
8
- export type CollectionData<T extends LivequeryBaseEntity> = (CollectionStream<T> & Pick<CollectionObservable<T>, 'add' | 'fetch_more' | 'filter' | 'reload' | 'reset' | 'trigger' | 'update' | '$changes'> & {
8
+ export type CollectionRef = string | undefined | '' | null | false;
9
+ export type CollectionData<T extends LivequeryBaseEntity> = (CollectionStream<T> & Pick<CollectionObservable<T>, 'add' | 'fetch_more' | 'fetch_prev' | 'reset' | 'trigger' | 'update' | '$changes' | 'filter'> & {
9
10
  empty: boolean;
10
11
  loaded: boolean;
12
+ ref: CollectionRef;
13
+ filters: CollectionStream<T>['options'];
11
14
  });
12
- export type CollectionRef = string | undefined | '' | null | false;
13
- export declare const useCollectionData: <T extends LivequeryBaseEntity>(ref: CollectionRef, collection_options?: Partial<useCollectionDataOptions<T>> & {
14
- vkl?: any;
15
- }) => CollectionData<T>;
15
+ export declare const useCollectionData: <T extends LivequeryBaseEntity>(ref: CollectionRef, collection_options?: Partial<useCollectionDataOptions<T>>) => CollectionData<T>;
@@ -11,12 +11,12 @@ export const useCollectionData = (ref, collection_options = {}) => {
11
11
  const { transporter } = useLiveQueryContext();
12
12
  const n = useRef(0);
13
13
  const lazy = collection_options.lazy;
14
- const [version, set_version] = useState(0);
14
+ const [, set_version] = useState(0);
15
15
  const client = useSyncMemo(() => {
16
16
  const client = new CollectionObservable(ref, { transporter, ...collection_options });
17
17
  n.current = 0;
18
18
  const subscription = client.subscribe(data => {
19
- if (collection_options.load_all && data.has_more) {
19
+ if (collection_options.load_all && data.paging.has?.next) {
20
20
  client.fetch_more();
21
21
  }
22
22
  else {
@@ -30,19 +30,23 @@ export const useCollectionData = (ref, collection_options = {}) => {
30
30
  return [client, () => subscription.unsubscribe()];
31
31
  }, [ref]);
32
32
  const loaded = n.current > 0;
33
- const empty = loaded && !client.value.loading && client.value.items.length == 0;
33
+ const $ = client.$.getValue();
34
+ const empty = loaded && !$.loading && $.items.length == 0;
34
35
  const result = {
35
- ...client.value,
36
+ ...$,
36
37
  loaded,
37
38
  empty,
39
+ filters: $.options,
38
40
  add: assert(client?.add, client),
39
41
  fetch_more: assert(client?.fetch_more, client),
42
+ fetch_prev: assert(client?.fetch_prev, client),
40
43
  filter: assert(client?.filter, client),
41
- reload: assert(client?.reload, client),
44
+ // fetch_around_cursor: assert(client?.fetch_around_cursor, client),
42
45
  reset: assert(client?.reset, client),
43
46
  trigger: assert(client?.trigger, client),
44
47
  update: assert(client?.update, client),
45
48
  $changes: client?.$changes || new Subject(),
49
+ ref
46
50
  };
47
51
  return result;
48
52
  };
@@ -1,13 +1,9 @@
1
- import { CollectionOption } from "@livequery/client";
1
+ import { useCollectionDataOptions } from "./useCollectionData.js";
2
2
  import { LivequeryBaseEntity } from "@livequery/types";
3
- export type useDocumentDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = Omit<CollectionOption<T>, 'filters'> & {
4
- lazy?: boolean;
5
- };
6
- export declare const useDocumentData: <T extends {
7
- id: string;
8
- }>(ref: string | undefined | '' | null | false, options?: useDocumentDataOptions) => {
3
+ export type useDocumentDataOptions<T extends LivequeryBaseEntity = LivequeryBaseEntity> = Partial<Omit<useCollectionDataOptions<T>, 'filters'>>;
4
+ export declare const useDocumentData: <T extends LivequeryBaseEntity>(ref: string | undefined | "" | null | false, config?: useDocumentDataOptions<T>) => {
9
5
  item: import("@livequery/client").SmartQueryItem<T>;
10
- loading: boolean | undefined;
11
- error: import("@livequery/types").ErrorInfo | undefined;
6
+ loading: import("@livequery/client").LoadingIndicator | undefined;
7
+ error: boolean | undefined;
12
8
  $changes: import("rxjs").Subject<import("@livequery/types").UpdatedData<T>>;
13
9
  };
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { useCollectionData } from "./useCollectionData.js";
3
- export const useDocumentData = (ref, options) => {
4
- const { items, loading, error, $changes } = useCollectionData(ref, options);
3
+ export const useDocumentData = (ref, config = {}) => {
4
+ const { items, loading, error, $changes } = useCollectionData(ref, config);
5
5
  return {
6
6
  item: items[0],
7
7
  loading,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "url": "https://github.com/livequery/react"
5
5
  },
6
6
  "type": "module",
7
- "version": "1.0.110",
7
+ "version": "2.0.0",
8
8
  "description": "",
9
9
  "main": "build/index.js",
10
10
  "types": "build/index.d.ts",
@@ -12,12 +12,14 @@
12
12
  "build/**/*"
13
13
  ],
14
14
  "dependencies": {
15
- "@livequery/client": "^1.0.93"
15
+ "@livequery/client": "^2.0.0",
16
+ "rxjs": "^7.8.1"
16
17
  },
17
18
  "devDependencies": {
18
- "@livequery/types": "^1.0.82",
19
+ "@livequery/types": "^2.0.0",
19
20
  "@types/react": "^17.0.11",
20
- "react": "^17.0.2"
21
+ "react": "^17.0.2",
22
+ "typescript": "5.5.2"
21
23
  },
22
24
  "peerDependencies": {
23
25
  "react": "^18.0.0"