From ab2ac7878f6fe9515a3a7efd7cbf5638337d72b1 Mon Sep 17 00:00:00 2001 From: Eric Kryski Date: Sat, 29 Jun 2013 18:03:30 -0600 Subject: [PATCH] forgot that services become event emitters via the events mixin --- lib/services/memory.js | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/services/memory.js b/lib/services/memory.js index 686ff00fb..a6ce7e83d 100644 --- a/lib/services/memory.js +++ b/lib/services/memory.js @@ -1,5 +1,4 @@ var Proto = require('uberproto'); -var EventEmitter = require('events').EventEmitter; var util = require('util'); var error = require('../errors'); var _ = require('underscore'); @@ -9,7 +8,7 @@ var _ = require('underscore'); // you be able to sort by multiple attributes? // // ie. { sort: ['name', 'birthday'], order: 'ascending'} -var mutators = { +var filters = { sort: function (values, param) { return _.sortBy(values, function (item) { return item[param]; @@ -42,7 +41,7 @@ var MemoryService = Proto.extend({ var values = _.values(this.store); - _.each(mutators, function(handler, name) { + _.each(filters, function(handler, name) { values = params[name] ? handler(values, params[name]) : values; }); @@ -70,14 +69,12 @@ var MemoryService = Proto.extend({ data[this._id] = id; if (this.store[id]){ - if (cb) cb(new Error('A record with id: ' + id + ' already exists')); - return; + return cb(new Error('A record with id: ' + id + ' already exists')); } this.store[id] = data; - this.emit('created', data); - if (cb) cb(null, data); + cb(null, data); }, update: function (id, data, cb) { @@ -87,14 +84,10 @@ var MemoryService = Proto.extend({ self.store[id][key] = value; }); - this.emit('updated', this.store[id]); - - if (cb) cb(null, this.store[id]); - return; + return cb(null, this.store[id]); } - this.emit('error', 'Could not find record with ' + id); - if (cb) cb('Could not find record with ' + id); + cb('Could not find record with ' + id); }, destroy: function (id, params, cb) { @@ -106,15 +99,11 @@ var MemoryService = Proto.extend({ var deleted = this.store[id]; delete this.store[id]; - this.emit('destroyed', deleted); - - if (cb) cb(null, deleted); - return; + return cb(null, deleted); } - this.emit('error', 'Could not find record with ' + id); - if (cb) cb('Could not find record with ' + id); + cb('Could not find record with ' + id); } -}, EventEmitter.prototype); +}); module.exports = MemoryService;