@liveblocks/react 0.9.0 → 0.12.0-beta.10

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/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Client, RecordData, Others, Presence, Record, InitialStorageFactory, Room, User } from "@liveblocks/client";
1
+ import { Client, Others, Presence, LiveObject, LiveMap, User, LiveList } from "@liveblocks/client";
2
2
  import * as React from "react";
3
3
  declare type LiveblocksProviderProps = {
4
4
  children: React.ReactNode;
@@ -8,7 +8,7 @@ declare type LiveblocksProviderProps = {
8
8
  * Makes the Liveblocks client available in the component hierarchy below.
9
9
  */
10
10
  export declare function LiveblocksProvider(props: LiveblocksProviderProps): JSX.Element;
11
- declare type RoomProviderProps = {
11
+ declare type RoomProviderProps<TStorageRoot> = {
12
12
  /**
13
13
  * The id of the room you want to connect to
14
14
  */
@@ -18,6 +18,7 @@ declare type RoomProviderProps = {
18
18
  * If ommited, the default presence will be an empty object
19
19
  */
20
20
  defaultPresence?: () => Presence;
21
+ defaultStorageRoot?: TStorageRoot;
21
22
  children: React.ReactNode;
22
23
  };
23
24
  /**
@@ -25,14 +26,13 @@ declare type RoomProviderProps = {
25
26
  * When this component is unmounted, the current user leave the room.
26
27
  * That means that you can't have 2 RoomProvider with the same room id in your react tree.
27
28
  */
28
- export declare function RoomProvider({ id, children, defaultPresence, }: RoomProviderProps): JSX.Element;
29
+ export declare function RoomProvider<TStorageRoot>({ id, children, defaultPresence, defaultStorageRoot, }: RoomProviderProps<TStorageRoot>): JSX.Element;
29
30
  /**
30
31
  * Returns the presence of the current user of the current room, and a function to update it.
31
32
  * It is different from the setState function returned by the useState hook from React.
32
33
  * You don't need to pass the full presence object to update it.
33
34
  *
34
- * ### Example
35
- * ``` typescript
35
+ * @example
36
36
  * import { useMyPresence } from "@liveblocks/react";
37
37
  *
38
38
  * const [myPresence, updateMyPresence] = useMyPresence();
@@ -40,7 +40,6 @@ export declare function RoomProvider({ id, children, defaultPresence, }: RoomPro
40
40
  * updateMyPresence({ y: 0 });
41
41
  *
42
42
  * // At the next render, "myPresence" will be equal to "{ x: 0, y: 0 }"
43
- * ```
44
43
  */
45
44
  export declare function useMyPresence<T extends Presence>(): [
46
45
  T,
@@ -50,8 +49,7 @@ export declare function useMyPresence<T extends Presence>(): [
50
49
  * useUpdateMyPresence is similar to useMyPresence but it only returns the function to update the current user presence.
51
50
  * If you don't use the current user presence in your component, but you need to update it (e.g. live cursor), it's better to use useUpdateMyPresence to avoid unnecessary renders.
52
51
  *
53
- * ### Example
54
- * ``` typescript
52
+ * @example
55
53
  * import { useUpdateMyPresence } from "@liveblocks/react";
56
54
  *
57
55
  * const updateMyPresence = useUpdateMyPresence();
@@ -59,14 +57,12 @@ export declare function useMyPresence<T extends Presence>(): [
59
57
  * updateMyPresence({ y: 0 });
60
58
  *
61
59
  * // At the next render, the presence of the current user will be equal to "{ x: 0, y: 0 }"
62
- * ```
63
60
  */
64
61
  export declare function useUpdateMyPresence<T extends Presence>(): (overrides: Partial<T>) => void;
65
62
  /**
66
63
  * Returns an object that lets you get information about all the the users currently connected in the room.
67
64
  *
68
- * ### Example
69
- * ``` typescript
65
+ * @example
70
66
  * import { useOthers } from "@liveblocks/react";
71
67
  *
72
68
  * const others = useOthers();
@@ -80,40 +76,34 @@ export declare function useUpdateMyPresence<T extends Presence>(): (overrides: P
80
76
  * return <Cursor key={connectionId} cursor={presence.cursor} />
81
77
  * })
82
78
  * }
83
- * ```
84
79
  */
85
80
  export declare function useOthers<T extends Presence>(): Others<T>;
86
81
  /**
87
82
  * Returns a callback that lets you broadcast custom events to other users in the room
88
83
  *
89
- * ### Example
90
- * ``` typescript
84
+ * @example
91
85
  * import { useBroadcastEvent } from "@liveblocks/react";
92
86
  *
93
87
  * const broadcast = useBroadcastEvent();
94
88
  *
95
89
  * broadcast({ type: "CUSTOM_EVENT", data: { x: 0, y: 0 } });
96
- * ```
97
90
  */
98
91
  export declare function useBroadcastEvent(): (event: any) => void;
99
92
  /**
100
93
  * useErrorListener is a react hook that lets you react to potential room connection errors.
101
94
  *
102
- * ### Example
103
- * ``` typescript
95
+ * @example
104
96
  * import { useErrorListener } from "@liveblocks/react";
105
97
  *
106
98
  * useErrorListener(er => {
107
99
  * console.error(er);
108
100
  * })
109
- * ```
110
101
  */
111
102
  export declare function useErrorListener(callback: (er: Error) => void): void;
112
103
  /**
113
104
  * useEventListener is a react hook that lets you react to event broadcasted by other users in the room.
114
105
  *
115
- * ### Example
116
- * ``` typescript
106
+ * @example
117
107
  * import { useEventListener } from "@liveblocks/react";
118
108
  *
119
109
  * useEventListener(({ connectionId, event }) => {
@@ -121,33 +111,24 @@ export declare function useErrorListener(callback: (er: Error) => void): void;
121
111
  * // Do something
122
112
  * }
123
113
  * });
124
- * ```
125
114
  */
126
115
  export declare function useEventListener<TEvent>(callback: ({ connectionId, event, }: {
127
116
  connectionId: number;
128
117
  event: TEvent;
129
118
  }) => void): void;
130
119
  /**
131
- * useCurrentUser is a react hook that lets you react to get the current user once it is connected to the room.
120
+ * Gets the current user once it is connected to the room.
132
121
  *
133
- * ### Example
134
- * ``` typescript
135
- * import { useCurrentUser } from "@liveblocks/react";
122
+ * @example
123
+ * import { useSelf } from "@liveblocks/react";
136
124
  *
137
- * const user = useCurrentUser();
138
- * ```
125
+ * const user = useSelf();
139
126
  */
140
- export declare function useCurrentUser<TPresence extends Presence = Presence>(): User<TPresence> | null;
141
- declare type StorageActions = {
142
- createRecord: Room["createRecord"];
143
- updateRecord: Room["updateRecord"];
144
- createList: Room["createList"];
145
- moveItem: Room["moveItem"];
146
- deleteItem: Room["deleteItem"];
147
- deleteItemById: Room["deleteItemById"];
148
- pushItem: Room["pushItem"];
149
- };
150
- export declare function useStorage<TRoot extends RecordData>(initialStorage: InitialStorageFactory<TRoot>): [root: Record<TRoot> | null, actions: StorageActions];
151
- export declare function useStorageActions(): StorageActions;
152
- export { createClient } from "@liveblocks/client";
153
- export type { Record, Client, List } from "@liveblocks/client";
127
+ export declare function useSelf<TPresence extends Presence = Presence>(): User<TPresence> | null;
128
+ export declare function useStorage<TRoot extends Record<string, any>>(): [
129
+ root: LiveObject<TRoot> | null
130
+ ];
131
+ export declare function useMap<TKey extends string, TValue>(key: string): LiveMap<TKey, TValue> | null;
132
+ export declare function useList<TValue>(key: string): LiveList<TValue> | null;
133
+ export declare function useObject<TData>(key: string): LiveObject<TData> | null;
134
+ export {};