E5E7 Remove Lodash by daffl · Pull Request #192 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"express": "^4.12.3",
"feathers-commons": "^0.3.0",
"feathers-errors": "^1.1.4",
"lodash": "^3.1.0",
"rubberduck": "^1.0.0",
"uberproto": "^1.2.0"
},
Expand Down
13 changes: 7 additions & 6 deletions src/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import makeDebug from 'debug';
import { stripSlashes } from 'feathers-commons';
import Uberproto from 'uberproto';
Expand All @@ -12,7 +11,7 @@ const Proto = Uberproto.extend({

export default {
init() {
_.extend(this, {
Object.assign(this, {
methods,
mixins: mixins(),
services: {},
Expand Down Expand Up @@ -54,7 +53,7 @@ export default {
},

use(location) {
let service, middleware = _(arguments)
let service, middleware = Array.from(arguments)
.slice(1)
.reduce(function (middleware, arg) {
if (typeof arg === 'function') {
Expand All @@ -70,7 +69,7 @@ export default {
after: []
});

const hasMethod = methods => _.some(methods, name =>
const hasMethod = methods => methods.some(name =>
(service && typeof service[name] === 'function'));

// Check for service (any object with at least one service method)
Expand All @@ -86,7 +85,9 @@ export default {

setup() {
// Setup each service (pass the app so that they can look up other services etc.)
_.each(this.services, (service, path) => {
Object.keys(this.services).forEach(path => {
const service = this.services[path];

debug(`Setting up service for \`${path}\``);
if (typeof service.setup === 'function') {
service.setup(this, path);
Expand All @@ -113,7 +114,7 @@ export default {

this.setup(server);
debug('Feathers application listening');

return server;
}
};
3 changes: 1 addition & 2 deletions src/feathers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
if(!global._babelPolyfill) { require('babel-polyfill'); }

import _ from 'lodash';
import express from 'express';
import Proto from 'uberproto';
import Application from './application';
Expand All @@ -22,4 +21,4 @@ export default function createApplication() {
createApplication.version = require('../package.json').version;

// Expose all express methods (like express.engine())
_.defaults(createApplication, express);
Object.assign(createApplication, express);
6 changes: 3 additions & 3 deletions src/mixins/event.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import rubberduck from 'rubberduck';
import { EventEmitter } from 'events';
import { hooks } from 'feathers-commons';
Expand All @@ -24,15 +23,16 @@ export default function(service) {
service.mixin(EventEmitter.prototype);
}

service._serviceEvents = _.isArray(service.events) ? service.events.slice() : [];
service._serviceEvents = Array.isArray(service.events) ? service.events.slice() : [];

// Pass the Rubberduck error event through
// TODO deal with error events properly
emitter.on('error', function (errors) {
service.emit('serviceError', errors[0]);
});

_.each(eventMappings, (event, method) => {
Object.keys(eventMappings).forEach(method => {
const event = eventMappings[method];
const alreadyEmits = service._serviceEvents.indexOf(event) !== -1;

if (typeof service[method] === 'function' && !alreadyEmits) {
Expand Down
13 changes: 6 additions & 7 deletions test/mixins/event.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assert from 'assert';
import _ from 'lodash';
import Proto from 'uberproto';
import { EventEmitter } from 'events';
import mixinEvent from '../../lib/mixins/event';
Expand Down Expand Up @@ -89,7 +88,7 @@ describe('Event mixin', () => {
it('updated', done => {
const FixtureService = Proto.extend({
update(id, data, params, cb) {
_.defer(function () {
setTimeout(function () {
cb(null, {
id: id,
name: data.name
Expand Down Expand Up @@ -123,7 +122,7 @@ describe('Event mixin', () => {
it('removed', done => {
const FixtureService = Proto.extend({
remove(id, params, cb) {
_.defer(function () {
setTimeout(function () {
cb(null, {
id: id
});
Expand Down Expand Up @@ -157,9 +156,9 @@ describe('Event mixin', () => {
];
const FixtureService = Proto.extend({
create(data, params, cb) {
_.defer(function () {
setTimeout(function () {
cb(null, fixture);
});
}, 20);
}
});

Expand All @@ -183,12 +182,12 @@ describe('Event mixin', () => {
const FixtureService = Proto.extend({
events: [ 'created' ],
create(data, params, cb) {
_.defer(function () {
setTimeout(function () {
cb(null, {
id: 10,
name: data.name
});
});
}, 20);
}
});

Expand Down
2AE3
0