@sprig-and-prose/sprig-ui-csr 0.1.0 → 0.1.1
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 +1 -1
- package/src/App.svelte +45 -1
package/package.json
CHANGED
package/src/App.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { onMount, onDestroy } from 'svelte';
|
|
2
3
|
import { loadUniverseGraph } from './lib/data/universeStore.js';
|
|
3
4
|
import { getCurrentRoute, navigate } from './lib/router.js';
|
|
4
5
|
import { theme } from './lib/stores/theme.js';
|
|
@@ -76,7 +77,50 @@
|
|
|
76
77
|
// Listen for link clicks
|
|
77
78
|
document.addEventListener('click', handleLinkClick);
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
// Set up Server-Sent Events for manifest updates
|
|
81
|
+
let eventSource = null;
|
|
82
|
+
|
|
83
|
+
onMount(() => {
|
|
84
|
+
if (typeof EventSource !== 'undefined') {
|
|
85
|
+
try {
|
|
86
|
+
eventSource = new EventSource('/api/events');
|
|
87
|
+
console.log('SSE EventSource created');
|
|
88
|
+
|
|
89
|
+
// Listen for manifest change events
|
|
90
|
+
eventSource.addEventListener('manifest', async (e) => {
|
|
91
|
+
console.log('SSE manifest event received:', e.data);
|
|
92
|
+
await loadManifest();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Optional: refetch on connection open to be safe
|
|
96
|
+
eventSource.addEventListener('open', () => {
|
|
97
|
+
console.log('SSE connection opened');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Handle errors (EventSource auto-reconnects, so we can ignore or log minimally)
|
|
101
|
+
eventSource.addEventListener('error', (e) => {
|
|
102
|
+
// EventSource will auto-reconnect, so we don't need to do anything
|
|
103
|
+
// Just log if needed for debugging
|
|
104
|
+
if (eventSource && eventSource.readyState === EventSource.CLOSED) {
|
|
105
|
+
console.log('SSE connection closed');
|
|
106
|
+
} else if (eventSource && eventSource.readyState === EventSource.CONNECTING) {
|
|
107
|
+
console.log('SSE reconnecting...');
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.error('Failed to create EventSource:', err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
loadManifest();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
onDestroy(() => {
|
|
119
|
+
if (eventSource) {
|
|
120
|
+
eventSource.close();
|
|
121
|
+
console.log('SSE EventSource closed');
|
|
122
|
+
}
|
|
123
|
+
});
|
|
80
124
|
</script>
|
|
81
125
|
|
|
82
126
|
<div class="app sprig-design">
|