<commit_before>Tabs = new Meteor.Collection('tabs');
Drinks = new Meteor.Collection('drinks');

if (Meteor.isClient) {
  Meteor.Router.add({
    '/': function () {
      return 'home';
    },

    '/tabs/:id':  function (id) {
      Session.set('tabId', id);
      return 'tab';
    }
  });

  Template.tab.drinks_menu = function(){
    return Drinks.find({});
  };

  Template.tab.ordered_drinks = function () {
    var tab = Tabs.findOne(Session.get('tabId'));

    if (!tab) return [];

    console.log("Drinks: ", tab.ordered_drinks);
    return tab.ordered_drinks;
  };

  Template.drink_from_menu.events({
    'click .buy_drink': function () {
      var drink = {name: this.name, price: this.price};

      console.log("this = ", this);

      // using 'this' doesn't work because it already has a '_id' field and 
      // you would be trying to render multiple drinks with the same id
      // which causes Spark to throw the "Can't create second landmark 
      // in same branch" error
      //Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: this}});
      
      // either ensure that the objects you want Spark to render have a 
      // unique id or leave off the _id completely and let Spark do it for you
      Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: drink}});
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    Meteor.Router.add({
      '/tabs/:id.xml': function(id) {
        return Tabs.findOne(id).owner;
      }
    });

    if (Tabs.find().count() === 0) {
      Tabs.insert({_id:id, ordered_drinks:[]});
    }

    if (Drinks.find().count() === 0) {
      Drinks.insert({name: "Screwdriver", price: "5.00"});
      Drinks.insert({name: "Rum and Coke", price: "5.50"});
      Drinks.insert({name: "Kilkenny's", price: "8.00"});
    }
  });
}<commit_msg>create initial tab on server start<commit_after>Tabs = new Meteor.Collection('tabs');
Drinks = new Meteor.Collection('drinks');

if (Meteor.isClient) {
  Meteor.Router.add({
    '/': function () {
      return 'home';
    },

    '/tabs/:id':  function (id) {
      Session.set('tabId', id);
      return 'tab';
    }
  });

  Template.tab.drinks_menu = function(){
    return Drinks.find({});
  };

  Template.tab.ordered_drinks = function () {
    var tab = Tabs.findOne(Session.get('tabId'));

    if (!tab) return [];

    console.log("Drinks: ", tab.ordered_drinks);
    return tab.ordered_drinks;
  };

  Template.drink_from_menu.events({
    'click .buy_drink': function () {
      var drink = {name: this.name, price: this.price};

      console.log("this = ", this);

      // using 'this' doesn't work because it already has a '_id' field and 
      // you would be trying to render multiple drinks with the same id
      // which causes Spark to throw the "Can't create second landmark 
      // in same branch" error
      //Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: this}});
      
      // either ensure that the objects you want Spark to render have a 
      // unique id or leave off the _id completely and let Spark do it for you
      Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: drink}});
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    Meteor.Router.add({
      '/tabs/:id.xml': function(id) {
        return Tabs.findOne(id).owner;
      }
    });

    if (Tabs.find().count() === 0) {
      Tabs.insert({_id:"1", ordered_drinks:[]});
    }

    if (Drinks.find().count() === 0) {
      Drinks.insert({name: "Screwdriver", price: "5.00"});
      Drinks.insert({name: "Rum and Coke", price: "5.50"});
      Drinks.insert({name: "Kilkenny's", price: "8.00"});
    }
  });
}
{'fraction_non_alphanumeric': 0.1736073553272039, 'fraction_numerical': 0.006219578150351541, 'mean_word_length': 2.7363636363636363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6353754', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1224, 'n_words': 305}