Following the tutorials from this site: http://blog.krawaller.se/posts/the-reflux-data-flow-model/
I'm looking at replacing var chatRef
to a dummy data instead of using new Firebase(...)
as shown in the author example. Baffled how exactly this line read?
chatRef.on("value",this.updateChat.bind(this));
What is "value" and how bind
work?
Tried to use var chatRef = {0: "Hello", 1: "Hello"}
produce Uncaught TypeError: undefined is not a function
chatRef appears to be an event emitter with at least one custom function (push).
You could mock it like this:
// you'll need to include an event emitter library
var chatRef = new EventEmitter();
chatRef.push = function(data, cb){
// if push emits a value event? not sure if it does
this.emit('value', {val: function(){ return data });
cb(null);
}
// emit a fake message every second
setInterval(function(){
chatRef.push({text: "hey", from: "me", to: "them"}, function(){})
}, 1000);
If you don't get it, you should read up on event emitters.
For the .bind
call google Function.prototoype.bind
. In this case the bind just ensures that when the callback is called, it has the correct this
value.