Permalink
Browse files

[refactor] Simplify dealing with arguments in Couch views

  • Loading branch information...
1 parent d265bc7 commit 8611bad2d2d9f39ef7e807c8a95bd3df5cd6fac6 @mmalecki mmalecki committed Oct 3, 2012
Showing with 10 additions and 7 deletions.
  1. +10 −7 lib/resourceful/engines/couchdb/view.js
@@ -61,14 +61,17 @@ exports.filter = function (name /* [options], filter */) {
// resource.someFilter('targetKey');
// resoure.someFilter({ startKey: 0, endKey: 1 });
//
- R[name] = function (/* [param], callback */) {
- var that = this,
- args = Array.prototype.slice.call(arguments),
- callback = args.pop(),
- param = args.pop() || {},
- path = [this.resource, name].join('/');
+ R[name] = function (param, callback) {
+ var that = this,
+ path = [this.resource, name].join('/'),
+ params;
- var params = (typeof(param) === 'object' && !Array.isArray(param)) ? param : { key: param };
+ if (typeof param === 'function') {
+ callback = param;
+ param = {};
+ }
+
+ params = (typeof(param) === 'object' && !Array.isArray(param)) ? param : { key: param };
if (options) {
Object.keys(options).forEach(function (key) {

1 comment on commit 8611bad

Contributor

pksunkara commented on 8611bad Oct 3, 2012

Good one. It's a lot less confusing for new contributors now.

Please sign in to comment.