create-wirejs-app 2.0.63 → 2.0.65-realtime

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-wirejs-app",
3
- "version": "2.0.63",
3
+ "version": "2.0.65-realtime",
4
4
  "description": "Initializes a wirejs package.",
5
5
  "author": "Jon Wire",
6
6
  "license": "MIT",
@@ -3,7 +3,8 @@ import {
3
3
  DistributedTable,
4
4
  FileService,
5
5
  PassThruParser,
6
- withContext
6
+ withContext,
7
+ RealtimeService
7
8
  } from 'wirejs-resources';
8
9
 
9
10
  const userTodos = new DistributedTable('app', 'userTodos', {
@@ -23,6 +24,8 @@ const userTodos = new DistributedTable('app', 'userTodos', {
23
24
  const wikiPages = new FileService('app', 'wikiPages');
24
25
  const authService = new AuthenticationService('app', 'core-users');
25
26
 
27
+ const realtimeService = new RealtimeService('app', 'realtime');
28
+
26
29
  export const auth = authService.buildApi();
27
30
 
28
31
  export type Todo = {
@@ -32,6 +35,15 @@ export type Todo = {
32
35
  list: string;
33
36
  };
34
37
 
38
+ export const messaging = withContext(context => ({
39
+ async publish(room: string, message: string) {
40
+ realtimeService.publish(room, message);
41
+ },
42
+ async getRoom(room: string) {
43
+ return realtimeService.getStream(room);
44
+ }
45
+ }));
46
+
35
47
  export const todos = withContext(context => ({
36
48
  async read(list?: string): Promise<Todo[]> {
37
49
  const user = await auth.requireCurrentUser(context);
@@ -11,11 +11,11 @@
11
11
  "dompurify": "^3.2.3",
12
12
  "marked": "^15.0.6",
13
13
  "wirejs-dom": "^1.0.41",
14
- "wirejs-resources": "^0.1.58",
15
- "wirejs-components": "^0.1.1"
14
+ "wirejs-resources": "^0.1.60-realtime",
15
+ "wirejs-components": "^0.1.3-realtime"
16
16
  },
17
17
  "devDependencies": {
18
- "wirejs-scripts": "^3.0.56",
18
+ "wirejs-scripts": "^3.0.58-realtime",
19
19
  "typescript": "^5.7.3"
20
20
  },
21
21
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { html } from 'wirejs-dom/v2';
1
+ import { html, hydrate } from 'wirejs-dom/v2';
2
2
  import { Main } from '../layouts/main.js';
3
3
 
4
4
  export async function generate() {
@@ -10,6 +10,7 @@ export async function generate() {
10
10
  <ul>
11
11
  <li><a href='/todo-app.html'>Todo App</a></li>
12
12
  <li><a href='/simple-wiki/index.html'>Simple Wiki</a></li>
13
+ <li><a href='/realtime-test.html'>Realtime Test</a></li>
13
14
  </ul>
14
15
  </div>`
15
16
  })
@@ -0,0 +1,37 @@
1
+ import { html, attribute, hydrate, list } from 'wirejs-dom/v2';
2
+ import { Main } from '../layouts/main.js';
3
+ import { messaging } from 'my-api';
4
+
5
+ async function App() {
6
+ const self = html`<div id='app'>
7
+ <h4>Realtime Test</h4>
8
+ ${list('messages', (message: string) => html`<div>${message}</div>`)}
9
+ <div>
10
+ <form onsubmit=${(event: Event) => {
11
+ event.preventDefault();
12
+ messaging.publish(null, 'test', self.data.message);
13
+ self.data.message = '';
14
+ }}>
15
+ <input type='text' value=${attribute('message', '' as string)} />
16
+ <input type='submit' value='Send' />
17
+ </form>
18
+ </div>
19
+ </div>`.onadd(async () => {
20
+ const roomStream = await messaging.getRoom(null, 'test');
21
+ roomStream.subscribe({
22
+ onmessage: (message: string) => {
23
+ self.data.messages.push(message);
24
+ }
25
+ });
26
+ })
27
+ return self;
28
+ }
29
+
30
+ export async function generate() {
31
+ return Main({
32
+ pageTitle: 'Welcome!',
33
+ content: await App()
34
+ })
35
+ }
36
+
37
+ hydrate('app', App);