Created
September 21, 2012 21:02
-
-
Save gabrielhpugliese/3763872 to your computer and use it in GitHub Desktop.
onbeforeunload meteor
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
Names = new Meteor.Collection("names"); | |
Name = { | |
remove : function(name, room) { | |
return Names.remove({ | |
name : name, | |
room : room, | |
host : PARENT // It's a string | |
}); | |
}, | |
get : function(name, room) { | |
return Names.findOne({ | |
name : name, | |
room : room, | |
host : PARENT | |
}); | |
}, | |
set : function(name, room) { | |
return Names.insert({ | |
name : name, | |
room : room, | |
host : PARENT | |
}); | |
} | |
}; | |
// This does not work :( | |
window.onbeforeunload = function(){ | |
var test = Name.remove(Session.get('name'), Session.get('room')); | |
return test.toString(); | |
}; | |
// But this alerts! How ?! | |
window.onbeforeunload = function(){ | |
var test = Name.get(Session.get('name'), Session.get('room')); | |
return test.toString(); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Name.get is a purely client-side call, which looks in our local cache. No methods!
Name.remove has to make server-side changes, so it does methods.