Permalink
Browse files

Add notes and fix some bad code

  • Loading branch information...
1 parent 4cf3815 commit e489aa661cb5066ba3c5447076e2961dc8e063c7 @vesln committed May 9, 2012
Showing with 79 additions and 31 deletions.
  1. +1 −1 lib/app.js
  2. +46 −10 lib/cli.js
  3. +10 −9 lib/commands.js
  4. +2 −2 lib/formatter.js
  5. +3 −2 lib/storage.js
  6. +17 −7 lib/todos.js
View
@@ -11,7 +11,7 @@
var flatiron = require('flatiron');
/**
- * The application object.
+ * Application.
*
* @type {Object}
*/
View
@@ -6,39 +6,75 @@
*/
/**
- * The application object.
+ * Application.
*
* @type {Object}
*/
var app = module.exports = require('./app');
/**
+ * Storage.
+ *
+ * @type {Object}
+ */
+var storage = require('./storage');
+
+/**
+ * Todos.
+ *
+ * @type {Function}
+ */
+var Todos = require('./todos'); // TODO: wtf?
+
+/**
* Commands.
*
* @type {Object}
*/
-var commands = require('./commands').init(require('./todos').init(require('./storage')));
+var commands = require('./commands')
+
+commands.init(new Todos(storage));
+
+// TODO: more docs
-// Version.
+/**
+ * Version.
+ */
app.cmd(/version/, commands.version);
-// Lists all todo items.
+/**
+ * List todos.
+ */
app.cmd(/ls/, commands.list);
-// Clears the whole todo.
+/**
+ * Clear a todo item.
+ */
app.cmd(/clear/, commands.clear);
-// Marks a todo item as done.
+/**
+ * Mark todo item as finished.
+ */
app.cmd(/check (.+)/, commands.check);
-// Marks a todo item as not done yet.
+/**
+ * Undo a todo item.
+ */
app.cmd(/undo (.+)/, commands.undo);
-// Removes a todo item.
+/**
+ * Destroy a todo item.
+ */
app.cmd(/rm (.+)/, commands.destroy);
-// Writes todo to file.
+/**
+ * Destroy a todo item.
+ *
+ * TODO: Fix me.
+ */
app.cmd(/write (.+)/, commands.write);
-// Adds new todo item.
+/**
+ * Create a new todo item.
+ */
app.cmd(/(.+)/, commands.add);
View
@@ -6,7 +6,7 @@
*/
/**
- * Commands namespace.
+ * Commands.
*
* @type {Object}
*/
@@ -50,8 +50,9 @@ var format = require('./formatter').format;
var fs = require('fs');
/**
- * Initializes the commands by given todos.
+ * Initialize the commands by given todos.
*
+ * @TODO: Fix me
* @api public
*/
commands.init = function(todos) {
@@ -60,7 +61,7 @@ commands.init = function(todos) {
}
/**
- * Prints current version.
+ * Print current version.
*
* @api public
*/
@@ -69,7 +70,7 @@ commands.version = function() {
};
/**
- * Lists todo items.
+ * List todo items.
*
* @api public
*/
@@ -80,7 +81,7 @@ commands.list = function() {
};
/**
- * Marks an item as done.
+ * Mark an item as done.
*
* @param {String} Number.
* @api public
@@ -100,7 +101,7 @@ commands.undo = function(num) {
};
/**
- * Deletes an item.
+ * Delete an item.
*
* @param {String} Todo item number.
* @api public
@@ -110,12 +111,11 @@ commands.destroy = function(num) {
};
/**
- * Clears the whole todo item.
+ * Clear the whole todo list.
*
- * @param {String} Todo item number.
* @api public
*/
-commands.clear = function(num) {
+commands.clear = function() {
commands.todos.clear();
};
@@ -134,6 +134,7 @@ commands.add = function(item) {
*
* @param {String} File location/name
* @api public
+ * @TODO: Fix me. I am not working.
*/
commands.write = function(filename) {
filename || (filename = "~/todo.txt");
View
@@ -6,12 +6,12 @@
*/
/**
- * Module dependencies.
+ * Dependencies.
*/
var colors = require('colors');
/**
- * Formatter namespace.
+ * Formatter.
*
* @type {Object}
*/
View
@@ -6,7 +6,7 @@
*/
/**
- * Module dependencies.
+ * Dependencies.
*/
var Storr = require('storr');
var path = require('path');
@@ -15,11 +15,12 @@ var path = require('path');
* Database path.
*
* @type {String}
+ * @TODO: This should be configurable.
*/
var db = path.join(__dirname, '..', 'data', 'db.json');
/**
- * Storage object.
+ * Storage.
*
* @type {Object}
*/
View
@@ -5,17 +5,25 @@
* MIT License.
*/
-var Todos = module.exports = function(storage) {
+/**
+ * Todos constructor.
+ *
+ * @param {Object} storage
+ * @api public
+ */
+function Todos(storage) {
this.storage = storage;
};
-Todos.init = function(storage) {
- return new Todos(storage);
-};
-
-Todos.prototype.all = function(callback) {
+/**
+ * Fetch all items.
+ *
+ * @params {Function} cb
+ * @api public
+ */
+Todos.prototype.all = function(cb) {
this.storage.get('items', function(err, items) {
- callback(items || []);
+ cb(items || []);
});
};
@@ -65,3 +73,5 @@ Todos.prototype._update = function(items) {
});
}.bind(this));
};
+
+module.exports = Todos;

0 comments on commit e489aa6

Please sign in to comment.