Method call once - yet executes twice?

Hi - i just noticed something when going one of my projects… T and (count) when logged are called twice? I figured it might have something to do with the multiple collection calls but not entirely sure.
A penny for your thoughts?

updateRoom: function(name, user){
    if (! Meteor.userId()) {
      throw new Meteor.Error("not-authorized");
    }
    check(name, String);
    check(user, String);
    var currentUser = Meteor.users.findOne({_id: Meteor.userId()});
    console.log('t');
    if(currentUser.admin){
      if(name != null && name != undefined){
        if(user != null && user != undefined){
          var currentRoom = Rooms.findOne({roomname: name});
          var count = Rooms.find({roomname: name, participants: user}).count();
          console.log(count);
          if(count === 0){
            Rooms.update({ _id: currentRoom._id},{$push: { participants: user}});
            Push.send({
              from: '',
              title: 'xxx',
              text: 'xx: ' + name,
              badge: 1,
              sound: "default",
              query: {userId: user}
            });
          }else if(check === 1){
            //remove user
          }
        }
      }
    }else {
        throw new Meteor.Error("not-authorized");
    }
  },
Template.userList.events({
  "click .item": function(event, template){
    Meteor.call('updateRoom', Session.get('roomname'), this._id);
    template.$(event.currentTarget).toggleClass('active-target');
  }
});

Do you have multiple .item objects? The docs state:

If a selector matches multiple elements that an event bubbles to, it will be called multiple times, for example in the case of ‘click div’ or ‘click *’.

and end up with this:

Returning false from a handler is the same as calling both stopImmediatePropagation and preventDefault on the event.

Which sounds like it may be what you want :smile:

How did i miss this? Thank you :smiley:

1 Like