Last active
January 13, 2016 17:18
-
-
Save linusthe3rd/ae41e2742231579ad4e7 to your computer and use it in GitHub Desktop.
Revisions
-
linusthe3rd revised this gist
Jan 13, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ var loadUser = function (id) { } var subscribeToNotifications = function(id) { // only subscribe to notifications if we have a web socket open if (notifications.isConnected()) { notifications.subscribe("users."+id, onNotification) -
linusthe3rd revised this gist
Jun 24, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ var subscribeToNotifications = function(id) { // only subscribe to notifications if if (notifications.isConnected()) { notifications.subscribe("users."+id, onNotification) .done(function () { loadUser(id); }); -
linusthe3rd created this gist
Jun 17, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ // ...other instantiation logic... var userID = getIDFromPageURI(); var user = null; var loadUser = function (id) { // GET the latest state of the user from the backend $.get("/api/user" + id) .done(function (response) { if (!user) { // if the user variable is NOT defined yet, create a new instance of a UserModel. user = new UserModel(response); } else { // If the user variable IS defined, fill in missing data UserModel.fill(user, response); } }); } var subscribeToNotifications = function(id) { // only subscribe to notifications if if (notifications.isConnected()) { notifications.subscribe("users."+id) .done(function () { loadUser(id); }); } } var onNotification = function (data) { if (!user) { // If the user variable is NOT defined, create a new instance of the user model. user = new UserModel(data); } else { // If the user variable IS defined, merge the new data into the existing model UserModel.merge(user, data); } } // Now that the page is defined, load the data from the backend and subscribe to notifications loadUser(userID); subscribeToNotifications(userID); // ...other instantiation logic...