Mixing files with client, lib and server code in the same folder


#1

The code blocks could be parsed into client, lib and server removing the need for having 3 separate files in 3 different locations. Example of a single file containing all required code:

posts.js

//CLIENT or //client etc
Meteor.subscribe('Posts');    

//LIB
Router('/posts');
Posts = new Mongo.Collection("posts");

//SERVER
Meteor.publish("posts", function () {
  return Posts.find({ createdBy: this.userId });
});

Organisational structures and folders of client-side, server-side, lib could be simplified.


#2
if (Meteor.isClient) {
	Meteor.subscribe('Posts');
}

Router('/posts');
Posts = new Mongo.Collection("posts");

if (Meteor.isServer) {
	Meteor.publish("posts", function () {
	  return Posts.find({ createdBy: this.userId });
	});
}

But it’s very costly to check every file instead of just checking files in /server/-folder etc


#3

This would be a nightmare for code assistance in IDE’s.

@benjick’s suggestion, which already is the case with meteor, does provide context an scope.

But mind you, that code would still end up both in client and server and anyone reading the source on the client may find out about what your app does on the server side.


#4

When you build or hit save in development, meteor would check for errors etc, then it would split posts.js into 3 files and it would save fragments accordingly to /server/posts.js /lib/posts.js and /client/posts.js without me having to maintain 3 files in 3 different locations.

I am aware of Meteor.isClient() and not disputing the logic for /server /client etc folders


#5

What do you mean by nightmare for IDE’s? Which IDE do you use?


#6

Any ide that uses static code analysis for code completion. Webstorm or ternjs enabled vim, atom, sublime.

Namely, within your proposed notation:

//client
foo = "foo";

//server
bar = foo;

This should raise an error since foo is undefined on the server. But ide will accept this to be correct since they are within the same js file and contextually, bar should be "foo". If these were separate files or in the same file but confined within if (Meteor.isPLATFORM) it would not be problem.