Created
September 5, 2011 02:24
-
-
Save jmoyers/1193923 to your computer and use it in GitHub Desktop.
Example state update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
entity.id [or] user.92329D39-6F5C-4520-ABFC-AAB64544E172 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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