Skip to content

Commit

Permalink
Revert "more lodash modularization"
Browse files Browse the repository at this point in the history
This reverts commit c4fa530.
  • Loading branch information
PieterGit committed Jul 22, 2018
1 parent bee8ee1 commit b13c274
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 42 deletions.
7 changes: 3 additions & 4 deletions lib/admin_plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var _find = require('lodash/find');
var _each = require('lodash/each');
var _ = require('lodash');

function init() {
var allPlugins = [
Expand All @@ -13,14 +12,14 @@ function init() {

function plugins(name) {
if (name) {
return _find(allPlugins, {name: name});
return _.find(allPlugins, {name: name});
} else {
return plugins;
}
}

plugins.eachPlugin = function eachPlugin(f) {
_each(allPlugins, f);
_.each(allPlugins, f);
};

plugins.createHTML = function createHTML(client) {
Expand Down
11 changes: 4 additions & 7 deletions lib/api/activity/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

var _forEach = require('lodash/forEach');
var _isNil = require('lodash/isNil');
var _isArray = require('lodash/isArray');

var _ = require('lodash');
var consts = require('../../constants');
var moment = require('moment');

Expand Down Expand Up @@ -39,7 +36,7 @@ function configure(app, wares, ctx) {
ctx.activity.list(req.query, function(err, results) {
var d1 = null;

_forEach(results, function clean(t) {
_.forEach(results, function clean(t) {

var d2 = null;

Expand All @@ -58,7 +55,7 @@ function configure(app, wares, ctx) {
}
});

if (!_isNil(d1)) res.setHeader('Last-Modified', d1.toUTCString());
if (!_.isNil(d1)) res.setHeader('Last-Modified', d1.toUTCString());

if (ifModifiedSince && d1.getTime() <= moment(ifModifiedSince).valueOf()) {
res.status(304).send({
Expand All @@ -78,7 +75,7 @@ function configure(app, wares, ctx) {
function post_response(req, res) {
var activity = req.body;

if (!_isArray(activity)) {
if (!_.isArray(activity)) {
activity = [activity];
};

Expand Down
7 changes: 4 additions & 3 deletions lib/api/alexa/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var moment = require('moment');
var _each = require('lodash/each');
var _ = require('lodash');


function configure (app, wares, ctx, env) {
var entries = ctx.entries;
Expand All @@ -20,15 +21,15 @@ function configure (app, wares, ctx, env) {
if (plugin.alexa) {
if (plugin.alexa.intentHandlers) {
console.log(plugin.name + ' is Alexa enabled');
_each(plugin.alexa.intentHandlers, function (route) {
_.each(plugin.alexa.intentHandlers, function (route) {
if (route) {
ctx.alexa.configureIntentHandler(route.intent, route.intentHandler, route.routableSlot, route.slots);
}
});
}
if (plugin.alexa.rollupHandlers) {
console.log(plugin.name + ' is Alexa rollup enabled');
_each(plugin.alexa.rollupHandlers, function (route) {
_.each(plugin.alexa.rollupHandlers, function (route) {
console.log('Route');
console.log(route);
if (route) {
Expand Down
18 changes: 7 additions & 11 deletions lib/api/entries/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict';

var _last = require('lodash/last');
var _isNil = require('lodash/isNil');
var _first = require('lodash/first');
var _includes = require('lodash/includes');

var _ = require('lodash');
var consts = require('../../constants');
var es = require('event-stream');
var sgvdata = require('sgvdata');
Expand Down Expand Up @@ -81,11 +77,11 @@ function configure(app, wares, ctx) {

function ifModifiedSinceCTX(req, res, next) {

var lastEntry = _last(ctx.ddata.sgvs);
var lastEntry = _.last(ctx.ddata.sgvs);
var lastEntryDate = null;

if (!_isNil(lastEntry)) {
lastEntryDate = new Date(_last(ctx.ddata.sgvs).mills);
if (!_.isNil(lastEntry)) {
lastEntryDate = new Date(_.last(ctx.ddata.sgvs).mills);
res.setHeader('Last-Modified', lastEntryDate.toUTCString());
}

Expand Down Expand Up @@ -144,10 +140,10 @@ function configure(app, wares, ctx) {

res.entries.sort(compare);

var lastEntry = _first(res.entries);
var lastEntry = _.first(res.entries);
var lastEntryDate = null;

if (!_isNil(lastEntry)) {
if (!_.isNil(lastEntry)) {
if (lastEntry.mills) lastEntryDate = new Date(lastEntry.mills);
if (!lastEntry.mills && lastEntry.date) lastEntryDate = new Date(lastEntry.date);
res.setHeader('Last-Modified', lastEntryDate.toUTCString());
Expand Down Expand Up @@ -630,7 +626,7 @@ curl -s -g 'http://localhost:1337/api/v1/times/20{14..15}/T{13..18}:{00..15}'.js
* by default.
*/
function prep_storage(req, res, next) {
if (req.params.storage && _includes(['entries', 'treatments', 'devicestatus'], req.params.storage)) {
if (req.params.storage && _.includes(['entries', 'treatments', 'devicestatus'], req.params.storage)) {
req.storage = ctx[req.params.storage];
} else {
req.storage = ctx.entries;
Expand Down
4 changes: 2 additions & 2 deletions lib/api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

function create (env, ctx) {
var _each = require('lodash/each')
var _ = require('lodash')
, express = require('express')
, app = express( )
;
Expand All @@ -22,7 +22,7 @@ function create (env, ctx) {

if (env.settings.enable) {
app.extendedClientSettings = ctx.plugins && ctx.plugins.extendedClientSettings ? ctx.plugins.extendedClientSettings(env.extendedSettings) : {};
_each(env.settings.enable, function (enable) {
_.each(env.settings.enable, function (enable) {
console.info('enabling feature:', enable);
app.enable(enable);
});
Expand Down
13 changes: 5 additions & 8 deletions lib/api/properties.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

var _isEmpty = require('lodash/isEmpty');
var _filter = require('lodash/filter');
var _pick = require('lodash/pick');

var _ = require('lodash');
var express = require('express');
var sandbox = require('../sandbox')();

Expand All @@ -25,21 +22,21 @@ function create (env, ctx) {
ctx.plugins.setProperties(sbx);

function notEmpty (part) {
return ! _isEmpty(part);
return ! _.isEmpty(part);
}

var segments = _filter(req.path.split('/'), notEmpty);
var segments = _.filter(req.path.split('/'), notEmpty);

var selected = [ ];

if (segments.length > 0) {
selected = _filter(segments[0].split(','), notEmpty);
selected = _.filter(segments[0].split(','), notEmpty);
}

var result = sbx.properties;

if (selected.length > 0) {
result = _pick(sbx.properties, selected);
result = _.pick(sbx.properties, selected);
}

if (req.query && req.query.pretty) {
Expand Down
11 changes: 4 additions & 7 deletions lib/api/treatments/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

var _forEach = require('lodash/forEach');
var _isNil = require('lodash/isNil');
var _isArray = require('lodash/isArray');

var _ = require('lodash');
var consts = require('../../constants');
var moment = require('moment');

Expand Down Expand Up @@ -39,7 +36,7 @@ function configure(app, wares, ctx) {
ctx.treatments.list(req.query, function(err, results) {
var d1 = null;

_forEach(results, function clean(t) {
_.forEach(results, function clean(t) {
t.carbs = Number(t.carbs);
t.insulin = Number(t.insulin);

Expand All @@ -60,7 +57,7 @@ function configure(app, wares, ctx) {
}
});

if (!_isNil(d1)) res.setHeader('Last-Modified', d1.toUTCString());
if (!_.isNil(d1)) res.setHeader('Last-Modified', d1.toUTCString());

if (ifModifiedSince && d1.getTime() <= moment(ifModifiedSince).valueOf()) {
res.status(304).send({
Expand All @@ -80,7 +77,7 @@ function configure(app, wares, ctx) {
function post_response(req, res) {
var treatments = req.body;

if (!_isArray(treatments)) {
if (!_.isArray(treatments)) {
treatments = [treatments];
};

Expand Down

0 comments on commit b13c274

Please sign in to comment.