So,one of the things I like about NodeJS and Websockets is that i can set certain things to happen when messages / certain triggers are sent back and forth (blink the cursor, or change the background color of the div for the new info, etc.
I’m trying to use observeChanges from the Meteor API, but I’m definitely having issues (what’s new with me, right?)
On my client I have
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { MyCollection } from '../imports/api/myCollection.js';
Template.showChanges.onCreated(function changesOnCreated() {
Meteor.subscribe('myCollection');
});
import './main.html';
Template.showChanges.helpers({
messages() {
return MyCollection.find({});
},
test: function () {
var count = 0;
var query = MyCollection.find({});
query.observeChanges({
added: function (id, message) {
count++;
console.log(myCollection.message + " brings the total to " + count + " messages.");
document.write("Message Added. Count is: " + count);
},
changed: function (id, message) {
count++;
console.log(MyCollection.message + " was changed.");
document.write("Message changed. Count increased: " + count);
},
removed: function () {
count--;
console.log("Lost one. We're now down to " + count + " admins.");
document.write("Message removed. Count decreased: " + count);
}
});
},
});
My first helper works fine, but I get nothing from the second ‘test’ helper with the observe changes in it. If you have suggestions, or a better way to detect changes to data, and make updates to DOM, let me know.