Skip to content

Instantly share code, notes, and snippets.

@jmoyers
Created September 5, 2011 02:24
Show Gist options
  • Save jmoyers/1193923 to your computer and use it in GitHub Desktop.
Save jmoyers/1193923 to your computer and use it in GitHub Desktop.
Example state update
entity.id [or] user.92329D39-6F5C-4520-ABFC-AAB64544E172
var EventEmitter = require('events').EventEmitter,
uuid = require('node-uuid');
var network = new EventEmitter();
function User(network){
// The attributes we're interested in tracking
this.attributes = {
first_name: "",
last_name: "",
email: ""
};
// Uniquely identify the model
this.id = uuid();
// Subscribe to events about this particular model
network.on("user." + this.id, function(state){
// And our model is in sync
this.attributes = state;
}.bind(this));
}
var user = new User(network);
network.emit("user.92329D39-6F5C-4520-ABFC-AAB64544E172", {
first_name: "Joshua",
last_name: "Moyers",
email: "jmoyers [at] gmail.com"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment