Permalink
Browse files

Using Helpers#getCallback instead of custom code

  • Loading branch information...
1 parent 6a96bd4 commit ce715a65e6ab6ccbd11ba20e8fce776720877fd9 @yuchi yuchi committed Dec 12, 2011
Showing with 12 additions and 20 deletions.
  1. +12 −20 lib/store.js
View
32 lib/store.js
@@ -3,23 +3,18 @@ exports.setNohm = function (originalNohm) {
Nohm = originalNohm;
};
-var async = require('async');
+var async = require('async'),
+ h = require(__dirname + '/helpers');
var noop = function () {};
/**
* Saves the object by either creating, or updating it.
*/
-exports.save = function save(options, callback) {
+exports.save = function save(options) {
- if (!callback) {
- if (typeof options === 'function') {
- callback = options;
- options = {};
- } else {
- callback = noop;
- }
- }
+ var callback = h.getCallback(arguments);
+ options = (typeof options !== 'function') && options ? options : {};
var self = this,
id_tries = 0,
@@ -29,7 +24,10 @@ exports.save = function save(options, callback) {
var generateId = function () {
idGenerated = true;
- var id = new Date() * -1 + Math.ceil(Math.random()*1e6); // this is only a temporary id. it's negative so there's a way to identify some corrupted data if there's a redis failure between the first write of this model and the id change to its final real id
+ // this is only a temporary id. it's negative so there's a way to identify some
+ // corrupted data if there's a redis failure between the first write of this
+ // model and the id change to its final real id
+ var id = new Date() * -1 + Math.ceil(Math.random()*1e6);
id_tries++;
self.exists(id, function (exists) {
if (exists && id_tries < 500) {
@@ -250,16 +248,10 @@ var __update = function __update(all, silent, callback) {
* Remove an objet from the database.
* Note: Does not destroy the js object or its properties itself!
*/
-exports.remove = function remove(options, callback) {
+exports.remove = function remove(options) {
- if (!callback) {
- if (typeof options === 'function') {
- callback = options;
- options = {};
- } else {
- callback = noop;
- }
- }
+ var callback = h.getCallback(arguments);
+ options = (typeof options !== 'function') && options ? options : {};
var self = this,
silent = !!options.silent;

0 comments on commit ce715a6

Please sign in to comment.