Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of _.compact #1209

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/logger-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class LoggerFactory {
opts = [opts];
}

this.appenders = _.compact(opts).map(o => {
this.appenders = opts.filter(Boolean).map(o => {
// Built-in shorthand
if (isString(o))
return Loggers.resolve({ type: o, options: { level: globalLogLevel } });
Expand Down Expand Up @@ -118,7 +118,7 @@ class LoggerFactory {
const broker = this.broker;
const appenders = this.appenders;

const logHandlers = _.compact(appenders.map(app => app.getLogHandler(bindings)));
const logHandlers = appenders.map(app => app.getLogHandler(bindings)).filter(Boolean);
const hasNewLogEntryMiddleware =
broker.middlewares && broker.middlewares.registeredHooks.newLogEntry;

Expand Down
2 changes: 1 addition & 1 deletion src/metrics/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MetricRegistry {
? this.opts.reporter
: [this.opts.reporter];

this.reporter = _.compact(reporters).map(r => {
this.reporter = reporters.filter(Boolean).map(r => {
const reporter = Reporters.resolve(r);
reporter.init(this);
return reporter;
Expand Down
7 changes: 3 additions & 4 deletions src/middlewares/action-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

"use strict";

const _ = require("lodash");
const { isFunction, isString, match } = require("../utils");

module.exports = function actionHookMiddleware(broker) {
Expand Down Expand Up @@ -43,13 +42,13 @@ module.exports = function actionHookMiddleware(broker) {
if (isString(hooks)) return service && isFunction(service[hooks]) ? service[hooks] : null;

if (Array.isArray(hooks)) {
return _.compact(
hooks.map(h => {
return hooks
.map(h => {
if (isString(h)) return service && isFunction(service[h]) ? service[h] : null;

return h;
})
);
.filter(Boolean);
}

return hooks;
Expand Down
2 changes: 1 addition & 1 deletion src/registry/discoverers/etcd3.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class Etcd3Discoverer extends BaseDiscoverer {
})

.then(packets => {
_.compact(packets).map(packet => {
packets.filter(Boolean).map(packet => {
if (packet.sender == this.broker.nodeID) return;

removeFromArray(prevNodes, packet.sender);
Expand Down
8 changes: 4 additions & 4 deletions src/service-broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class ServiceBroker {
registerMiddlewares(userMiddlewares) {
// Register user middlewares
if (Array.isArray(userMiddlewares) && userMiddlewares.length > 0) {
_.compact(userMiddlewares).forEach(mw => this.middlewares.add(mw));
userMiddlewares.filter(Boolean).forEach(mw => this.middlewares.add(mw));
}

if (this.options.internalMiddlewares) {
Expand Down Expand Up @@ -1024,8 +1024,8 @@ class ServiceBroker {
if (!Array.isArray(serviceNames)) serviceNames = [serviceNames];

serviceNames = _.uniq(
_.compact(
serviceNames.map(x => {
serviceNames
.map(x => {
if (utils.isPlainObject(x) && x.name) {
if (Array.isArray(x.version)) {
return x.version.map(v =>
Expand All @@ -1038,7 +1038,7 @@ class ServiceBroker {
return x;
}
})
)
.filter(Boolean)
);

if (serviceNames.length == 0) return this.Promise.resolve({ services: [], statuses: [] });
Expand Down
24 changes: 13 additions & 11 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ class Service {
* @returns {Object} Merged schema
*/
mergeSchemaUniqArray(src, target) {
return _.uniqWith(_.compact(flatten([src, target])), _.isEqual);
return _.uniqWith(flatten([src, target]).filter(Boolean), _.isEqual);
}

/**
Expand Down Expand Up @@ -720,9 +720,9 @@ class Service {
const modHook = wrapToArray(src[k][k2]);
const resHook = wrapToArray(target[k][k2]);

target[k][k2] = _.compact(
flatten(k === "before" ? [resHook, modHook] : [modHook, resHook])
);
target[k][k2] = flatten(
k === "before" ? [resHook, modHook] : [modHook, resHook]
).filter(Boolean);
});
});

Expand Down Expand Up @@ -752,9 +752,9 @@ class Service {
const modHook = wrapToArray(srcAction.hooks[k]);
const resHook = wrapToArray(targetAction.hooks[k]);

srcAction.hooks[k] = _.compact(
flatten(k === "before" ? [resHook, modHook] : [modHook, resHook])
);
srcAction.hooks[k] = flatten(
k === "before" ? [resHook, modHook] : [modHook, resHook]
).filter(Boolean);
});
}

Expand Down Expand Up @@ -789,9 +789,11 @@ class Service {
const modEvent = wrapToHandler(src[k]);
const resEvent = wrapToHandler(target[k]);

let handler = _.compact(
flatten([resEvent ? resEvent.handler : null, modEvent ? modEvent.handler : null])
);
let handler = flatten([
resEvent ? resEvent.handler : null,
modEvent ? modEvent.handler : null
]).filter(Boolean);

if (handler.length === 1) handler = handler[0];

target[k] = _.defaultsDeep(modEvent, resEvent);
Expand All @@ -810,7 +812,7 @@ class Service {
* @returns {Object} Merged schema
*/
mergeSchemaLifecycleHandlers(src, target) {
return _.compact(flatten([target, src]));
return flatten([target, src]).filter(Boolean);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Tracer {
? this.opts.exporter
: [this.opts.exporter];

this.exporter = _.compact(exporters).map(r => {
this.exporter = exporters.filter(Boolean).map(r => {
const exporter = Exporters.resolve(r);
exporter.init(this);
return exporter;
Expand Down
2 changes: 1 addition & 1 deletion src/transporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class BaseTransporter {
);
}

return this.broker.Promise.all(_.compact(flatten(p, true)));
return this.broker.Promise.all(flatten(p, true).filter(Boolean));
})
);
});
Expand Down