@pluv/react 0.1.3 → 0.2.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,5 +1,5 @@
1
1
 
2
- > @pluv/react@0.1.3 build /home/runner/work/pluv/pluv/packages/react
2
+ > @pluv/react@0.2.0 build /home/runner/work/pluv/pluv/packages/react
3
3
  > tsup src/index.ts --format esm,cjs --dts --external react
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,9 +9,9 @@
9
9
  ESM Build start
10
10
  CJS Build start
11
11
  ESM dist/index.mjs 7.70 KB
12
- ESM ⚡️ Build success in 86ms
13
- CJS dist/index.js 9.71 KB
14
- CJS ⚡️ Build success in 88ms
12
+ ESM ⚡️ Build success in 61ms
13
+ CJS dist/index.js 9.70 KB
14
+ CJS ⚡️ Build success in 69ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 5192ms
16
+ DTS ⚡️ Build success in 5341ms
17
17
  DTS dist/index.d.ts 3.92 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @pluv/react
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 95b5ef8: breaking: update PluvRoom.broadcast api
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [95b5ef8]
12
+ - @pluv/client@0.2.0
13
+ - @pluv/types@0.1.2
14
+
3
15
  ## 0.1.3
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -26,7 +26,9 @@
26
26
  <img src="https://img.shields.io/badge/docs-coming%20soon!-blue" alt="Docs coming soon!" />
27
27
  </p>
28
28
 
29
- <img src="https://github.com/pluv-io/pluv/blob/master/assets/demo-events.gif?raw=true" alt="Demo" />
29
+ <p align="center">
30
+ <img src="https://github.com/pluv-io/pluv/blob/master/assets/demo-events.gif?raw=true" alt="Demo" />
31
+ </p>
30
32
 
31
33
  ## `@pluv/react`
32
34
 
@@ -130,12 +132,9 @@ export const MyRoom: FC<Record<string, never>> = () => {
130
132
  return (
131
133
  <button
132
134
  onClick={() => {
133
- broadcast({
134
- type: "SEND_MESSAGE",
135
- data: {
136
- // TypeScript will require that message is typed as string
137
- message: "Hello world!",
138
- }
135
+ broadcast("SEND_MESSAGE", {
136
+ // TypeScript will require that message is typed as string
137
+ message: "Hello world!",
139
138
  });
140
139
  }}
141
140
  type="button"
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PluvRoomDebug, WebSocketConnection, UserInfo, PluvRoom, InferYjsSharedTypeJson, PluvClient } from '@pluv/client';
2
2
  export { AbstractType, ConnectionState, createClient, y } from '@pluv/client';
3
3
  import * as _pluv_types from '@pluv/types';
4
- import { JsonObject, InputZodLike, IOLike, Id, InferEventMessage, InferIOInput, InferIOOutput, IOEventMessage } from '@pluv/types';
4
+ import { JsonObject, InputZodLike, IOLike, InferIOInput, Id, InferIOOutput, IOEventMessage } from '@pluv/types';
5
5
  export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
6
6
  import { ReactNode, FC, Dispatch } from 'react';
7
7
  import { AbstractType } from 'yjs';
@@ -30,7 +30,7 @@ interface SubscriptionHookOptions<T extends unknown> {
30
30
  type UpdateMyPresenceAction<TPresence extends JsonObject> = Partial<TPresence> | ((oldPresence: TPresence | null) => Partial<TPresence>);
31
31
  interface CreateRoomBundle<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> {
32
32
  PluvRoomProvider: FC<PluvRoomProviderProps<TIO, TPresence, TStorage>>;
33
- usePluvBroadcast: <TMessage extends Id<InferEventMessage<InferIOInput<TIO>>>>() => (message: TMessage) => void;
33
+ usePluvBroadcast: () => <TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => void;
34
34
  usePluvConnection: <T extends unknown = WebSocketConnection>(selector: (connection: WebSocketConnection) => T, options?: SubscriptionHookOptions<Id<T>>) => Id<T>;
35
35
  usePluvEvent: <TType extends keyof InferIOOutput<TIO>>(type: TType, callback: (data: Id<IOEventMessage<TIO, TType>>) => void) => void;
36
36
  usePluvMyPresence: <T extends unknown = TPresence>(selector?: (myPresence: TPresence) => T, options?: SubscriptionHookOptions<Id<T> | null>) => [
package/dist/index.js CHANGED
@@ -112,8 +112,8 @@ var createRoomBundle = (client, options = {}) => {
112
112
  const usePluvBroadcast = () => {
113
113
  const room = usePluvRoom();
114
114
  return (0, import_react3.useCallback)(
115
- (message) => {
116
- room.broadcast(message);
115
+ (event, data) => {
116
+ room.broadcast(event, data);
117
117
  },
118
118
  [room]
119
119
  );
@@ -174,10 +174,10 @@ var createRoomBundle = (client, options = {}) => {
174
174
  (value) => {
175
175
  const oldMyPresence = room.getMyPresence();
176
176
  const presence = typeof value === "function" ? value(oldMyPresence) : value;
177
- room.broadcast({
178
- type: "$UPDATE_PRESENCE",
179
- data: { presence }
180
- });
177
+ room.broadcast(
178
+ "$UPDATE_PRESENCE",
179
+ { presence }
180
+ );
181
181
  },
182
182
  [room]
183
183
  );
package/dist/index.mjs CHANGED
@@ -79,8 +79,8 @@ var createRoomBundle = (client, options = {}) => {
79
79
  const usePluvBroadcast = () => {
80
80
  const room = usePluvRoom();
81
81
  return useCallback2(
82
- (message) => {
83
- room.broadcast(message);
82
+ (event, data) => {
83
+ room.broadcast(event, data);
84
84
  },
85
85
  [room]
86
86
  );
@@ -141,10 +141,10 @@ var createRoomBundle = (client, options = {}) => {
141
141
  (value) => {
142
142
  const oldMyPresence = room.getMyPresence();
143
143
  const presence = typeof value === "function" ? value(oldMyPresence) : value;
144
- room.broadcast({
145
- type: "$UPDATE_PRESENCE",
146
- data: { presence }
147
- });
144
+ room.broadcast(
145
+ "$UPDATE_PRESENCE",
146
+ { presence }
147
+ );
148
148
  },
149
149
  [room]
150
150
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/react",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "@pluv/client React.js bindings",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  "@types/use-sync-external-store": "^0.0.3",
21
21
  "fast-deep-equal": "^3.1.3",
22
22
  "use-sync-external-store": "^1.2.0",
23
- "@pluv/client": "^0.1.3",
23
+ "@pluv/client": "^0.2.0",
24
24
  "@pluv/types": "^0.1.2"
25
25
  },
26
26
  "peerDependencies": {
@@ -34,7 +34,7 @@
34
34
  "typescript": "^4.9.4",
35
35
  "yjs": "^13.5.44",
36
36
  "@pluv/tsconfig": "^0.1.2",
37
- "eslint-config-pluv": "^0.1.2"
37
+ "eslint-config-pluv": "^0.1.3"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup src/index.ts --format esm,cjs --dts --external react",
@@ -8,7 +8,6 @@ import type {
8
8
  import type { PluvRoom } from "@pluv/client";
9
9
  import type {
10
10
  Id,
11
- InferEventMessage,
12
11
  InferIOInput,
13
12
  InferIOOutput,
14
13
  InputZodLike,
@@ -68,9 +67,10 @@ export interface CreateRoomBundle<
68
67
  PluvRoomProvider: FC<PluvRoomProviderProps<TIO, TPresence, TStorage>>;
69
68
 
70
69
  // hooks
71
- usePluvBroadcast: <
72
- TMessage extends Id<InferEventMessage<InferIOInput<TIO>>>
73
- >() => (message: TMessage) => void;
70
+ usePluvBroadcast: () => <TEvent extends keyof InferIOInput<TIO>>(
71
+ event: TEvent,
72
+ data: Id<InferIOInput<TIO>[TEvent]>
73
+ ) => void;
74
74
  usePluvConnection: <T extends unknown = WebSocketConnection>(
75
75
  selector: (connection: WebSocketConnection) => T,
76
76
  options?: SubscriptionHookOptions<Id<T>>
@@ -185,14 +185,18 @@ export const createRoomBundle = <
185
185
 
186
186
  const usePluvRoom = () => useContext(PluvRoomContext);
187
187
 
188
- const usePluvBroadcast = <
189
- TMessage extends Id<InferEventMessage<InferIOInput<TIO>>>
190
- >(): ((message: TMessage) => void) => {
188
+ const usePluvBroadcast = (): (<TEvent extends keyof InferIOInput<TIO>>(
189
+ event: TEvent,
190
+ data: Id<InferIOInput<TIO>[TEvent]>
191
+ ) => void) => {
191
192
  const room = usePluvRoom();
192
193
 
193
194
  return useCallback(
194
- (message: TMessage) => {
195
- room.broadcast(message);
195
+ <TEvent extends keyof InferIOInput<TIO>>(
196
+ event: TEvent,
197
+ data: Id<InferIOInput<TIO>[TEvent]>
198
+ ) => {
199
+ room.broadcast(event, data);
196
200
  },
197
201
  [room]
198
202
  );
@@ -281,10 +285,10 @@ export const createRoomBundle = <
281
285
  ? value(oldMyPresence)
282
286
  : value;
283
287
 
284
- room.broadcast({
285
- type: "$UPDATE_PRESENCE",
286
- data: { presence },
287
- } as Id<InferEventMessage<InferIOInput<TIO>>>);
288
+ room.broadcast(
289
+ "$UPDATE_PRESENCE" as keyof InferIOInput<TIO>,
290
+ { presence } as any
291
+ );
288
292
  },
289
293
  [room]
290
294
  );