Skip to content

Commit

Permalink
Don't use sails-util for Lodash methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sgress454 committed Feb 2, 2016
1 parent 7ae836b commit 24a19bb
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/hooks/blueprints/index.js
Expand Up @@ -248,7 +248,7 @@ module.exports = function(sails) {
if (config.pluralize) {
baseRouteName = pluralize(baseRouteName);
}

var baseRoute = config.prefix + '/' + baseRouteName;
// Determine base route for RESTful service
// Note that restPrefix will always start with /
Expand Down Expand Up @@ -286,7 +286,7 @@ module.exports = function(sails) {
// -> or implicitly by globalId
// -> or implicitly by controller id
var routeConfig = sails.router.explicitRoutes[controllerId] || {};
var modelFromGlobalId = sails.util.findWhere(sails.models, {globalId: globalId});
var modelFromGlobalId = _.findWhere(sails.models, {globalId: globalId});
var modelId = config.model || routeConfig.model || (modelFromGlobalId && modelFromGlobalId.identity) || controllerId;

// If the orm hook is enabled, it has already been loaded by this time,
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/csrf/index.js
Expand Up @@ -61,7 +61,7 @@ module.exports = function(sails) {
}
};
// Add the csrfToken directly to the config'd routes, so that the CORS hook can process it
sails.config.routes = sails.util.extend(csrfRoute, sails.config.routes);
sails.config.routes = _.extend(csrfRoute, sails.config.routes);
},

initialize: function(cb) {
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/http/index.js
Expand Up @@ -165,7 +165,7 @@ module.exports = function(sails) {
sails.config.paths.public = path.resolve(sails.config.appPath, sails.config.paths.public);

// Merge in legacy `sails.config.express` object for backwards-compat.
sails.util.defaultsDeep(sails.config.http, sails.config.express||{});
_.defaultsDeep(sails.config.http, sails.config.express||{});

// If no custom middleware order is specified, make sure the default one is used.
// This lets you override default middleware without having to explicitly include the
Expand Down
6 changes: 3 additions & 3 deletions lib/hooks/moduleloader/index.js
Expand Up @@ -160,7 +160,7 @@ module.exports = function(sails) {
configure: function() {
if (sails.config.moduleLoaderOverride) {
var override = sails.config.moduleLoaderOverride(sails, this);
sails.util.extend(this, override);
_.extend(this, override);
if (override.configure) {
this.configure();
}
Expand Down Expand Up @@ -264,7 +264,7 @@ module.exports = function(sails) {
var env = sails.config.environment;
// Merge the configs, with env/*.js files taking precedence over others, and local.js
// taking precedence over everything
var config = sails.util.merge(
var config = _.merge(
async_data['config/*'],
async_data['config/env/**'],
async_data['config/env/*'],
Expand Down Expand Up @@ -330,7 +330,7 @@ module.exports = function(sails) {
flattenDirectories: true
}, bindToSails(function(err, supplements) {
if (err) {return cb(err);}
return cb(null, sails.util.merge(models, supplements));
return cb(null, _.merge(models, supplements));
}));
});
},
Expand Down
4 changes: 2 additions & 2 deletions lib/hooks/orm/normalize-datastore.js
Expand Up @@ -5,7 +5,7 @@
var path = require('path');
var fs = require('fs');
var Err = require('../../../errors');

var _ = require('lodash');

/**
* normalizeDatastore()
Expand Down Expand Up @@ -85,7 +85,7 @@ module.exports = function howto_normalizeDatastore(sails){
// Defaults connection object to its adapter's defaults
// TODO: pull this out into waterline core
var itsAdapter = sails.adapters[connectionObject.adapter];
connection = sails.util.merge({}, itsAdapter.defaults, connectionObject);
connection = _.merge({}, itsAdapter.defaults, connectionObject);

// If the adapter has a `registerCollection` method, it must be a v0.9.x adapter
if (itsAdapter.registerCollection) {
Expand Down
24 changes: 12 additions & 12 deletions lib/hooks/pubsub/index.js
Expand Up @@ -453,7 +453,7 @@ module.exports = function(sails) {

if (contexts === true || contexts == '*') {
contexts = this.getAllContexts();
} else if (sails.util.isString(contexts)) {
} else if (_.isString(contexts)) {
contexts = [contexts];
}

Expand Down Expand Up @@ -572,7 +572,7 @@ module.exports = function(sails) {
);
}

if (sails.util.isFunction(this.beforePublishUpdate)) {
if (_.isFunction(this.beforePublishUpdate)) {
this.beforePublishUpdate(id, changes, req, options);
}

Expand Down Expand Up @@ -724,7 +724,7 @@ module.exports = function(sails) {
// Broadcast to the model instance room
this.publish(id, this.identity, 'update', data, socketToOmit);

if (sails.util.isFunction(this.afterPublishUpdate)) {
if (_.isFunction(this.afterPublishUpdate)) {
this.afterPublishUpdate(id, changes, req, options);
}

Expand Down Expand Up @@ -755,7 +755,7 @@ module.exports = function(sails) {
);
}

if (sails.util.isFunction(this.beforePublishDestroy)) {
if (_.isFunction(this.beforePublishDestroy)) {
this.beforePublishDestroy(id, req, options);
}

Expand Down Expand Up @@ -840,7 +840,7 @@ module.exports = function(sails) {

}

if (sails.util.isFunction(this.afterPublishDestroy)) {
if (_.isFunction(this.afterPublishDestroy)) {
this.afterPublishDestroy(id, req, options);
}

Expand Down Expand Up @@ -900,7 +900,7 @@ module.exports = function(sails) {
}

// Lifecycle event
if (sails.util.isFunction(this.beforePublishAdd)) {
if (_.isFunction(this.beforePublishAdd)) {
this.beforePublishAdd(id, alias, idAdded, req);
}

Expand Down Expand Up @@ -961,7 +961,7 @@ module.exports = function(sails) {
}


if (sails.util.isFunction(this.afterPublishAdd)) {
if (_.isFunction(this.afterPublishAdd)) {
this.afterPublishAdd(id, alias, idAdded, req);
}

Expand Down Expand Up @@ -993,7 +993,7 @@ module.exports = function(sails) {
'.publishRemove(id, alias, idRemoved, [socketToOmit])`'
);
}
if (sails.util.isFunction(this.beforePublishRemove)) {
if (_.isFunction(this.beforePublishRemove)) {
this.beforePublishRemove(id, alias, idRemoved, req);
}

Expand Down Expand Up @@ -1043,7 +1043,7 @@ module.exports = function(sails) {

}

if (sails.util.isFunction(this.afterPublishRemove)) {
if (_.isFunction(this.afterPublishRemove)) {
this.afterPublishRemove(id, alias, idRemoved, req);
}

Expand Down Expand Up @@ -1085,15 +1085,15 @@ module.exports = function(sails) {

options = options || {};

if (sails.util.isUndefined(values[this.primaryKey])) {
if (_.isUndefined(values[this.primaryKey])) {
return sails.log.error(
'Invalid usage of publishCreate() :: ' +
'Values must have an `'+this.primaryKey+'`, instead got ::\n' +
util.inspect(values)
);
}

if (sails.util.isFunction(this.beforePublishCreate)) {
if (_.isFunction(this.beforePublishCreate)) {
this.beforePublishCreate(values, req);
}

Expand Down Expand Up @@ -1235,7 +1235,7 @@ module.exports = function(sails) {
this.introduce(values[this.primaryKey]);
}

if (sails.util.isFunction(this.afterPublishCreate)) {
if (_.isFunction(this.afterPublishCreate)) {
this.afterPublishCreate(values, req);
}

Expand Down
9 changes: 4 additions & 5 deletions lib/hooks/userconfig/index.js
Expand Up @@ -5,8 +5,7 @@ module.exports = function(sails) {
* Module dependencies
*/

var util = require('sails-util');

var _ = require('lodash');


/**
Expand All @@ -29,7 +28,7 @@ module.exports = function(sails) {
sails.log.verbose('Loading app config...');

// Grab reference to mapped overrides
var overrides = util.cloneDeep(sails.config);
var overrides = _.cloneDeep(sails.config);


// If appPath not specified yet, use process.cwd()
Expand All @@ -45,11 +44,11 @@ module.exports = function(sails) {
// Finally, extend user config with overrides
var config = {};

config = util.merge(userConfig, overrides);
config = _.merge(userConfig, overrides);

// Ensure final configuration object is valid
// (in case moduleloader fails miserably)
config = util.isObject(config) ? config : (sails.config || {});
config = _.isObject(config) ? config : (sails.config || {});

// Save final config into sails.config
sails.config = config;
Expand Down
14 changes: 7 additions & 7 deletions lib/router/bind.js
Expand Up @@ -39,23 +39,23 @@ function bind( /* path, target, verb, options */ ) {


// Bind a list of multiple functions in order
if (util.isArray(target)) {
if (_.isArray(target)) {
bindArray.apply(this, [path, target, verb, options]);
}
// Handle string redirects
// (to either public-facing URLs or internal routes)
else if (util.isString(target) && target.match(/^(https?:|\/)/)) {
else if (_.isString(target) && target.match(/^(https?:|\/)/)) {
bindRedirect.apply(this, [path, target, verb, options]);
}

// Bind a middleware function directly
else if (util.isFunction(target)) {
else if (_.isFunction(target)) {
bindFunction.apply(this, [path, target, verb, options]);
}

// If target is an object with a `target`, pull out the rest
// of the keys as route options and then bind the target.
else if (util.isPlainObject(target) && target.target) {
else if (_.isPlainObject(target) && target.target) {
var _target = _.cloneDeep(target.target);
options = _.merge(options, _.omit(target, 'target'));
bind.apply(this, [path, _target, verb, options]);
Expand Down Expand Up @@ -120,7 +120,7 @@ function bindArray(path, target, verb, options) {
sails.log.verbose('Ignoring empty array in `router.bind(' + path + ')`...');
} else {
// Bind each middleware fn
util.each(target, function(fn) {
_.each(target, function(fn) {
bind.apply(self,[path, fn, verb, options]);
});
}
Expand All @@ -140,7 +140,7 @@ function bindFunction(path, fn, verb, options) {
var skipAssetsRegex = /^[^?]*\/[^?/]+\.[^?/]+(\?.*)?$/;

// Make sure (optional) options is a valid plain object ({})
options = util.isPlainObject(options) ? _.cloneDeep(options) : {};
options = _.isPlainObject(options) ? _.cloneDeep(options) : {};
var _middlewareType = options._middlewareType || fn._middlewareType || (fn.name && ('FUNCTION: ' + fn.name));
sails.log.silly('Binding route :: ', verb || '', path, _middlewareType?('('+_middlewareType+')'):'');

Expand Down Expand Up @@ -221,7 +221,7 @@ function bindFunction(path, fn, verb, options) {
var skipRegexesWrapper = function(regexes, fn) {

// Remove anything that's not a regex
regexes = sails.util.compact(regexes.map(function(regex) {
regexes = _.compact(regexes.map(function(regex) {
if (regex instanceof RegExp) {
return regex;
}
Expand Down

0 comments on commit 24a19bb

Please sign in to comment.