Autoloading classes


#1

Hi,

So I’m trying to make a chat with Meteor, and I want to work with OOP, however I have a problem and I dont really know how to fix it.

app/server/ChatomaticServer.js:

/*
  # This code runs on the server
*/

console.log("Chatomatic launched");


class ChatomaticServer {
  constructor() {
    this.startUp();
  }

  startUp() {
    Meteor.startup(function() {
      // empty Chats
      console.log("Clearing chats...");
      Chats.remove({});
      // empty Rooms
      console.log("Clearing rooms");
      // displays current users registered
      console.log("Current users registered: %d", Users.find().count());
    });
  }
}

app/server/bootstrap.js

/*
  Collections
*/
Chats = new Mongo.Collection("Chats");
Rooms = new Mongo.Collection("Rooms");
Users = Meteor.users;


/*
  ChatomaticServer
*/
new ChatomaticServer();

I get the error message > “ReferenceError: ChatomaticServer is not defined”

when I put a console.log in Chatomatic.js, it displays it in the console (“Chatomatic launched”). Why can it not find the class ChatomaticServer?


#2

fix it myself:

ChatomaticServer = class ChatomaticServer {

constructor() {
this.startUp();
}


#3

Is there a particular reason you don’t use Blaze Components for that?


#4

define “that”? this is on the server side


#5

Right, my mistake.

I tried to make it 20 characters long but failed, so I’m adding this sentence.