@pluv/io 5.0.1 → 5.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <div align="center">
2
2
  <a href="https://pluv.io/docs/introduction">
3
- <img src="https://github.com/pluv-io/pluv/blob/master/assets/pluv-icon-192x192.png?raw=true" alt="Pluv.IO" width="156" style="border-radius:16px" />
3
+ <img src="https://github.com/pluv-io/pluv/blob/main/assets/pluv-icon-192x192.png?raw=true" alt="Pluv.IO" width="156" style="border-radius:16px" />
4
4
  </a>
5
5
  </div>
6
6
 
@@ -11,7 +11,7 @@
11
11
  <a href="https://www.npmjs.com/package/@pluv/io">
12
12
  <img src="https://img.shields.io/npm/v/@pluv/io" alt="npm @pluv/io" />
13
13
  </a>
14
- <a href="https://github.com/pluv-io/pluv/blob/master/LICENSE">
14
+ <a href="https://github.com/pluv-io/pluv/blob/main/LICENSE">
15
15
  <img alt="GitHub" src="https://img.shields.io/github/license/pluv-io/pluv" alt="License MIT" />
16
16
  </a>
17
17
  <a href="https://commitizen.github.io/cz-cli/">
@@ -39,25 +39,25 @@ Create your pluv.io backend
39
39
  ```ts
40
40
  // backend
41
41
  const io = createIO(
42
- platformNode({
43
- context: () => ({ db }),
44
- crdt: yjs,
45
- })
42
+ platformNode({
43
+ context: () => ({ db }),
44
+ crdt: yjs,
45
+ }),
46
46
  );
47
47
 
48
48
  export const ioServer = io.server({
49
- getInitialStorage: async ({ context: { db }, room }) => {
50
- return await db.room
51
- .findUnique({ where: { id: room } })
52
- .then((result) => result?.encodedState ?? null);
53
- },
54
- router: io.router({
55
- sendGreeting: io.procedure
56
- .input(z.object({ message: z.string() }))
57
- .broadcast(({ message }) => ({
58
- receiveGreeting: { message }
59
- }))
60
- })
49
+ getInitialStorage: async ({ context: { db }, room }) => {
50
+ return await db.room
51
+ .findUnique({ where: { id: room } })
52
+ .then((result) => result?.encodedState ?? null);
53
+ },
54
+ router: io.router({
55
+ sendGreeting: io.procedure
56
+ .input(z.object({ message: z.string() }))
57
+ .broadcast(({ message }) => ({
58
+ receiveGreeting: { message },
59
+ })),
60
+ }),
61
61
  });
62
62
  ```
63
63
 
@@ -67,29 +67,25 @@ Create your frontend client with your backend types
67
67
  // frontend
68
68
  const types = infer((i) => ({ io: i<typeof ioServer> }));
69
69
  const io = createClient({
70
- types,
71
- initialStorage: yjs.doc((t) => ({
72
- messages: t.array<string>("messages"),
73
- })),
74
- presence: z.object({
75
- selectionId: z.string().nullable()
76
- })
70
+ types,
71
+ initialStorage: yjs.doc((t) => ({
72
+ messages: t.array<string>("messages"),
73
+ })),
74
+ presence: z.object({
75
+ selectionId: z.string().nullable(),
76
+ }),
77
77
  });
78
78
 
79
- const {
80
- event,
81
- useBroadcast,
82
- useMyPresence,
83
- useOthers,
84
- useStorage
85
- } = createBundle(io);
79
+ const { event, useBroadcast, useMyPresence, useOthers, useStorage } = createBundle(io);
86
80
  ```
87
81
 
88
82
  Use powerful primitives to build realtime features
89
83
 
90
84
  ```tsx
91
85
  // react
92
- event.receiveGreeting.useEvent(({ data }) => { /* ... */});
86
+ event.receiveGreeting.useEvent(({ data }) => {
87
+ /* ... */
88
+ });
93
89
  // ^? const data: { message: string }
94
90
 
95
91
  const broadcast = useBroadcast();
@@ -98,20 +94,20 @@ broadcast.sendGreeting({ message: "hello world" });
98
94
  // ^? const sendGreeting: (data: { message: string }) => void
99
95
 
100
96
  const [mySelection, update] = useMyPresence((presence) => {
101
- // ^? const mySelection: string | null
102
- return presence.selectionId;
97
+ // ^? const mySelection: string | null
98
+ return presence.selectionId;
103
99
  });
104
100
 
105
101
  const others = useOthers((others) => {
106
- // ^? const others = string[]
107
- return others.map((other) => other.presence.selectionId);
102
+ // ^? const others = string[]
103
+ return others.map((other) => other.presence.selectionId);
108
104
  });
109
105
 
110
106
  const [
111
- messages,
112
- // ^? const messages: string[] | null
113
- sharedType
114
- // ^? YArray<string> | null
107
+ messages,
108
+ // ^? const messages: string[] | null
109
+ sharedType,
110
+ // ^? YArray<string> | null
115
111
  ] = useStorage("messages");
116
112
  ```
117
113
 
@@ -196,4 +192,4 @@ This software uses the following open source tooling and libraries:
196
192
 
197
193
  ## License
198
194
 
199
- [MIT](https://github.com/pluv-io/pluv/blob/master/LICENSE)
195
+ [MIT](https://github.com/pluv-io/pluv/blob/main/LICENSE)