- Kotlin Blueprints
- Ashish Belagali Hardik Trivedi Akshay Chordiya
- 136字
- 2021-07-02 21:50:16
Listening to message saved events
Storing the message in the database takes some amount of time and we want to update the UI or reflect the state of the UI after the message is successfully saved into the database. We specify an EventSource and add an EventListener to receive the callback when a new message is stored in the database.
When a new message is saved into the database the callback function of the event listener is called and we then plot the message on the map using ol.Feature:
/* Reactive: Event listener to get updates when new message is
saved */
var source = new EventSource("/message/subscribe");
// Callback function called on event update
source.addEventListener('message', function (e) {
var message = $.parseJSON(e.data);
var feature = new ol.Feature({
geometry: new ol.geom.Point(message.location.coordinates),
content: message.content
});
vectorSource.addFeature(feature);
}, false);
推薦閱讀
- The Complete Rust Programming Reference Guide
- Mastering JavaScript Object-Oriented Programming
- Java異步編程實(shí)戰(zhàn)
- Pandas Cookbook
- Developing Middleware in Java EE 8
- Apache Hive Essentials
- 算法大爆炸:面試通關(guān)步步為營
- INSTANT CakePHP Starter
- 零基礎(chǔ)學(xué)Java程序設(shè)計(jì)
- Mastering KnockoutJS
- Java Web開發(fā)就該這樣學(xué)
- 零基礎(chǔ)學(xué)C語言第2版
- SciPy Recipes
- QlikView Unlocked
- 軟件設(shè)計(jì)模式(Java版)