Skip to content

Commit

Permalink
upgrade lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenschobert committed Mar 9, 2016
1 parent e9b032a commit 15de3aa
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 64 deletions.
12 changes: 6 additions & 6 deletions lib/pimm.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@
* Adds and queued up middleware to the mach stack.
*/
.method('_loadMiddleware', function loadMiddleware() {
_.each(_.flatten([this._default_middleware, this._middleware]), function(middleware) {
_.each(_.flatten([this._default_middleware, this._middleware]), _.bind(function(middleware) {
this._stack.use.apply(this._stack, _.flatten([middleware.middleware, middleware.args]));
}, this);
}, this));
})

/**
Expand Down Expand Up @@ -223,20 +223,20 @@
* methods backing them up.
*/
.method('_normalizeRoutes', function normalizeRoutes() {
this._router.routes = _.filter(this._router.routes, function checkRoute(route) {
this._router.routes = _.filter(this._router.routes, _.bind(function checkRoute(route) {
var handler = _.isFunction(route.action) ? route.action : this._controller_manager.methodForSignature(route.action);
return _.isFunction(handler);
}, this);
}, this));
})

/**
* Maps all the routes to controller handlers.
*/
.method('_activateRoutes', function activateRoutes() {
_.each(this._router.routes, function activateRoute(route) {
_.each(this._router.routes, _.bind(function activateRoute(route) {
var handler = _.isFunction(route.action) ? route.action : this._controller_manager.methodForSignature(route.action);
this._stack[route.method](route.path, handler);
}, this);
}, this));
});

module.exports = Pimm;
Expand Down
12 changes: 6 additions & 6 deletions lib/pimm/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

Controller
.method('_getMethods', function getMethods() {
var handlers = _.filter(METHOD_NAMES, function(name) {
var handlers = _.filter(METHOD_NAMES, _.bind(function(name) {
return _.isFunction(this[name]);
}, this);
return _.reduce(handlers, function(acc, func) {
}, this));
return _.reduce(handlers, _.bind(function(acc, func) {
acc[func] = this[func].bind(this);
return acc;
}, {}, this);
}, this), {});
})

/**
Expand All @@ -38,7 +38,7 @@
return this;
}

_.each(methods, function wrapMethod(method) {
_.each(methods, _.bind(function wrapMethod(method) {
if (!_.isFunction(this[method])) {
return;
}
Expand All @@ -48,7 +48,7 @@
val = wrapper.apply(this, args);
return _.isUndefined(val) ? orig.apply(this, args) : val;
}, this));
}, this);
}, this));

return this;
});
Expand Down
8 changes: 4 additions & 4 deletions lib/pimm/controller_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
return acc;
}, {});

_.forIn(controllers, function mapControllerFile(Controller, path) {
_.forIn(controllers, _.bind(function mapControllerFile(Controller, path) {
var filePath = new Path({value: path}),
controllerName = new Path({value: filePath.withoutExtension()}).withoutPrefix(),
controller = {};
Expand All @@ -53,10 +53,10 @@
}

this.controllers[controllerName] = controller;
_.forIn(controller._instance._getMethods(), function addSubKeys(handler, name) {
_.forIn(controller._instance._getMethods(), _.bind(function addSubKeys(handler, name) {
controller[name] = handler.bind(controller._instance);
}, this);
}, this);
}, this));
}, this));

return this;
});
Expand Down
12 changes: 6 additions & 6 deletions lib/pimm/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
{call: 'delete', action: 'destroy', suffix: '/:id'},
{call: 'patch', action: 'update', suffix: '/:id'},
{call: 'put', action: 'replace', suffix: '/:id'}
], function mapResources(route) {
], _.bind(function mapResources(route) {
this[route.call](['/', resource, route.suffix].join(''), [resource, '#', route.action].join(''));
}, this);
}, this));
})

.method('resource', function resource(res) {
Expand All @@ -65,9 +65,9 @@
{call: 'delete', action: 'destroy', suffix: ''},
{call: 'patch', action: 'update', suffix: ''},
{call: 'put', action: 'replace', suffix: ''}
], function mapResource(route) {
], _.bind(function mapResource(route) {
this[route.call](['/', res, route.suffix].join(''), [res, '#', route.action].join(''));
}, this);
}, this));
})

/**
Expand All @@ -84,14 +84,14 @@
.method('namespace', function namespace(prefix, func) {
var newContext = {};

_.each(['get', 'post', 'patch', 'put', 'delete', 'resources', 'resource'], function bindNamespacedMethods(method) {
_.each(['get', 'post', 'patch', 'put', 'delete', 'resources', 'resource'], _.bind(function bindNamespacedMethods(method) {
newContext[method] = _.wrap(prefix, _.bind(function wrappedMethod(prefix, route, action) {
var newRoute = [prefix, '/', route].join(''),
newAction = [prefix, '/', action].join(''),
args = _.drop(arguments, 3);
return _.partial(this[method], newRoute, newAction).apply(this, args);
}, this));
}, this);
}, this));

func.call(newContext);
})
Expand Down
4 changes: 2 additions & 2 deletions lib/pimm/support/method_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
return _.has(METHODS_MAP, method) && _.isFunction(handler);
});

_.forIn(methods, function(handler, method) {
_.forIn(methods, _.bind(function(handler, method) {
var map = METHODS_MAP[method],
base = _.isString(this.basePath) ? this.basePath : '';
this.stack[map.method].call(this.stack, base + map.path, handler);
}, this);
}, this));

return this;
});
Expand Down
4 changes: 2 additions & 2 deletions lib/pimm/view_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@

return dir.load().bind(this)
.then(function() {
_.forIn(dir.files, function processFile(file, path) {
_.forIn(dir.files, _.bind(function processFile(file, path) {
var filePath = new Path({value: path}),
keyName = new Path({value: filePath.withoutExtension()}).withoutPrefix(),
fullPath = dirPath.resolve(path);
this.views[keyName] = {path: fullPath};
this.views[keyName].render = _.bind(this._render, this, fullPath);
}, this);
}, this));
return this;
});
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"bluebird": "^3.3.4",
"keylime": "^1.0.0",
"lodash": "^3.10.1",
"lodash": "^4.6.1",
"mach": "^1.3.8",
"recursive-readdir": "^1.1.3",
"consolidate": "^0.14.0"
Expand Down
Loading

0 comments on commit 15de3aa

Please sign in to comment.