Mercurial > code > home > repos > streamed-graph
comparison src/streamed_graph_client.ts @ 20:9ec3cbc8791a
build is running, but no tests, and lots of code is disabled
author | drewp@bigasterisk.com |
---|---|
date | Fri, 13 Dec 2019 01:18:00 -0800 |
parents | 7ca4ff2088c3 |
children | 8b4dc9e87b56 |
comparison
equal
deleted
inserted
replaced
19:23fa6402c728 | 20:9ec3cbc8791a |
---|---|
1 // from /my/site/homepage/www/rdf/streamed-graph.js | 1 // from /my/site/homepage/www/rdf/streamed-graph.js |
2 | 2 |
3 import { eachJsonLdQuad } from "./json_ld_quads"; | 3 import { eachJsonLdQuad } from "./json_ld_quads"; |
4 import { N3Store } from '../node_modules/@types/n3/index'; | 4 import { N3Store } from 'n3'; |
5 import { Store } from 'n3'; | 5 import { Store } from 'n3'; |
6 | 6 |
7 export class StreamedGraphClient { | 7 export class StreamedGraphClient { |
8 // holds a n3 Store, which is synced to a server-side | 8 // holds a n3 Store, which is synced to a server-side |
9 // store that sends patches over SSE | 9 // store that sends patches over SSE |
10 | 10 |
11 onStatus: (msg: string) => void; | 11 onStatus: (msg: string) => void; |
12 onGraphChanged: () => void; | 12 onGraphChanged: () => void; |
13 store: N3Store; | 13 store: N3Store; |
14 events: EventSource; | 14 events!: EventSource; |
15 constructor( | 15 constructor( |
16 eventsUrl: string, | 16 eventsUrl: string, |
17 onGraphChanged: () => void, | 17 onGraphChanged: () => void, |
18 onStatus: (status: string) => void, | 18 onStatus: (status: string) => void, |
19 prefixes: Array<Record<string, string>>, | 19 prefixes: Array<Record<string, string>>, |
69 }, 3000); | 69 }, 3000); |
70 }); | 70 }); |
71 | 71 |
72 this.events.addEventListener('fullGraph', async (ev) => { | 72 this.events.addEventListener('fullGraph', async (ev) => { |
73 this.onStatus('sync- full graph update'); | 73 this.onStatus('sync- full graph update'); |
74 await this.replaceFullGraph(ev.data); | 74 await this.replaceFullGraph((ev as MessageEvent).data); |
75 this.onStatus(`synced ${this.store.size}`); | 75 this.onStatus(`synced ${this.store.size}`); |
76 this.onGraphChanged(); | 76 this.onGraphChanged(); |
77 }); | 77 }); |
78 | 78 |
79 this.events.addEventListener('patch', async (ev) => { | 79 this.events.addEventListener('patch', async (ev) => { |
80 this.onStatus('sync- updating'); | 80 this.onStatus('sync- updating'); |
81 await this.patchGraph(ev.data); | 81 await this.patchGraph((ev as MessageEvent).data); |
82 this.onStatus(`synced ${this.store.size}`); | 82 this.onStatus(`synced ${this.store.size}`); |
83 this.onGraphChanged(); | 83 this.onGraphChanged(); |
84 }); | 84 }); |
85 this.onStatus('connecting...'); | 85 this.onStatus('connecting...'); |
86 } | 86 } |