Skip to content

Instantly share code, notes, and snippets.

@gabrielhpugliese
Created September 21, 2012 21:02
Show Gist options
  • Save gabrielhpugliese/3763872 to your computer and use it in GitHub Desktop.
Save gabrielhpugliese/3763872 to your computer and use it in GitHub Desktop.
onbeforeunload meteor
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();
};
@glasser
Copy link

glasser commented Sep 24, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment