isbn-sort/isbn_sort/static/dynamicUpdate.js

23 lines
583 B
JavaScript
Raw Normal View History

2024-04-05 17:47:15 +02:00
const listener = new EventSource("/app/listen");
listener.onmessage = (e) => {
let data = JSON.parse(e.data);
console.log(data);
switch (data.type) {
case "pong":
console.log("pong!");
break;
case "add_book":
viewAddBook(data.book);
break;
case "update_book":
viewUpdateBook(data.book);
break;
case "delete_book":
viewDeleteBook(data.book);
break;
default:
console.log("Unexpected response from SSE:", data);
}
};