Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Controllers are now simple objects

Views are now singletons
Services now export a function which return a singleton.
 - This was done as node-layers now supports non-prototypal layer objects.
  • Loading branch information...
commit 954fef8d188a2917efc9a374610cc9853a717f37 1 parent 3fca912
@dave-elkan authored
View
3  .gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+.gitingore
+node_modules
View
2  Readme.md
@@ -4,7 +4,7 @@ For more information see the blog post on [edave.net](http://www.edave.net/2011/
This example relies on a number of modules:
-* [Node 0.4.3](http://nodejs.org)
+* [Node 0.4.7](http://nodejs.org)
* [Express 2.0.0](http://expressjs.org)
* [Expresso 0.7.3](http://visionmedia.github.com/expresso/)
* [node-mongodb-native 0.9.1](https://github.com/christkv/node-mongodb-native)
View
3  app.js
@@ -1,6 +1,7 @@
/**
* Module dependencies.
*/
+// require.paths.unshift(__dirname + "/node_libraries")
var express = require('express'),
app = module.exports = express.createServer(),
@@ -52,7 +53,7 @@ app.configure('production', function() {
* The Layers module automatically loads the controllers, services and views from
* their respective directories
*/
-var wiring = require('./lib/wiring');
+var wiring = require('./layers/wiring');
new Layers(app, __dirname + '/layers', wiring, {
layers: [
"controllers",
View
8 layers/controllers/AuthorController.js
@@ -1,6 +1,4 @@
-AuthorController = function() {};
-
-AuthorController.prototype = {
+module.exports = {
displayAuthorList: function(req, res, callback) {
this.services.authorService.getList(callback);
@@ -14,6 +12,4 @@ AuthorController.prototype = {
this.services.authorService.getAuthorAndTheirBooks(authorKey, callback);
}
}
-};
-
-module.exports = AuthorController;
+};
View
8 layers/controllers/BookController.js
@@ -1,6 +1,4 @@
-BookController = function() {};
-
-BookController.prototype = {
+module.exports = {
getBookIndex: function(req, res, callback) {
this.services.bookService.getList(callback);
@@ -9,6 +7,4 @@ BookController.prototype = {
getBookByKey: function(req, res, callback) {
this.services.bookService.getBookAndItsAuthor(req.params.key, callback);
}
-};
-
-module.exports = BookController;
+};
View
8 layers/controllers/HomeController.js
@@ -1,9 +1,5 @@
-HomeController = function() {};
-
-HomeController.prototype = {
+module.exports = {
getAuthorAndBookList: function(req, res, callback) {
this.services.homeService.getAuthorAndBookList(callback);
}
-};
-
-module.exports = HomeController;
+};
View
2  layers/dao/Dao.js
@@ -84,7 +84,7 @@ Dao.prototype.read = function(params, callback) {
for (var field in params.selector) {
indexedFields.push([field, 1]);
}
-
+
self.ensureIndex(collection, indexedFields, function(error) {
if (error) {
callback(error);
View
4 layers/services/AuthorService.js
@@ -35,4 +35,6 @@ AuthorService.prototype.getAuthorAndTheirBooks = function(authorKey, callback) {
});
};
-module.exports = AuthorService;
+module.exports = function(app) {
+ return new AuthorService(app);
+};
View
4 layers/services/BookService.js
@@ -45,4 +45,6 @@ BookService.prototype.getBookAndItsAuthor = function(bookKey, callback) {
});
};
-module.exports = BookService;
+module.exports = function(app) {
+ return new BookService(app);
+};
View
6 layers/services/HomeService.js
@@ -26,7 +26,9 @@ HomeService.prototype.getAuthorAndBookList = function(callback) {
}
});
}
- })
+ });
};
-module.exports = HomeService;
+module.exports = function(app) {
+ return new HomeService(app);
+};
View
2  layers/views/HomeView.js
@@ -16,4 +16,4 @@ HomeView.prototype.getTitle = function() {
return "The Library";
};
-module.exports = HomeView;
+module.exports = new HomeView();
View
2  layers/views/JsonView.js
@@ -15,4 +15,4 @@ JsonView.prototype.render = function(req, res, result) {
res.send(result);
};
-module.exports = JsonView;
+module.exports = new JsonView;
View
2  layers/views/author/AuthorIndexView.js
@@ -12,4 +12,4 @@ AuthorIndexView.prototype.getTitle = function(result) {
return "Authors (" + result.length + ")";
};
-module.exports = AuthorIndexView;
+module.exports = new AuthorIndexView;
View
2  layers/views/author/AuthorView.js
@@ -29,4 +29,4 @@ AuthorView.prototype.getTemplate = function() {
return "author.jade";
};
-module.exports = AuthorView;
+module.exports = new AuthorView;
View
2  layers/views/book/BookIndexView.js
@@ -12,4 +12,4 @@ BookIndexView.prototype.getTitle = function(result) {
return "Books (" + result.length + ")";
};
-module.exports = BookIndexView;
+module.exports = new BookIndexView;
View
2  layers/views/book/BookView.js
@@ -16,4 +16,4 @@ BookView.prototype.getTemplate = function() {
return "book.jade";
};
-module.exports = BookView;
+module.exports = new BookView;
View
0  lib/wiring.js → layers/wiring.js
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.