Skip to content

Use ramda insead of lodash #230

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

Open
wants to merge 1 commit 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 lib/ArraySlice.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const negate = require('lodash/negate');
const complement = require('ramda/src/complement');

// Coerces an a parameter into a callback for matching elements.
// This accepts an element name, an element type and returns a
Expand Down Expand Up @@ -99,7 +99,7 @@ class ArraySlice {
*/
reject(callback, thisArg) {
callback = coerceElementMatchingCallback(callback);
return new ArraySlice(this.elements.filter(negate(callback), thisArg));
return new ArraySlice(this.elements.filter(complement(callback), thisArg));
}

/**
Expand Down
19 changes: 7 additions & 12 deletions lib/Namespace.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
const isNull = require('lodash/isNull');
const isString = require('lodash/isString');
const isNumber = require('lodash/isNumber');
const isBoolean = require('lodash/isBoolean');
const isObject = require('lodash/isObject');

const is = require('ramda/src/is');
const JSONSerialiser = require('./serialisers/JSONSerialiser');
const elements = require('./elements');

Expand Down Expand Up @@ -68,12 +63,12 @@ class Namespace {
// Add instance detection functions to convert existing objects into
// the corresponding refract elements.
this
.detect(isNull, elements.NullElement, false)
.detect(isString, elements.StringElement, false)
.detect(isNumber, elements.NumberElement, false)
.detect(isBoolean, elements.BooleanElement, false)
.detect(Array.isArray, elements.ArrayElement, false)
.detect(isObject, elements.ObjectElement, false);
.detect(v => v === null, elements.NullElement, false)
.detect(is(String), elements.StringElement, false)
.detect(is(Number), elements.NumberElement, false)
.detect(is(Boolean), elements.BooleanElement, false)
.detect(is(Array), elements.ArrayElement, false)
.detect(is(Object), elements.ObjectElement, false);

return this;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ObjectSlice.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const negate = require('lodash/negate');
const complement = require('ramda/src/complement');
const ArraySlice = require('./ArraySlice');

/**
Expand All @@ -13,7 +13,7 @@ class ObjectSlice extends ArraySlice {
}

reject(callback, thisArg) {
return this.filter(negate(callback.bind(thisArg)));
return this.filter(complement(callback.bind(thisArg)));
}

forEach(callback, thisArg) {
Expand Down
4 changes: 2 additions & 2 deletions lib/primitives/ArrayElement.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const negate = require('lodash/negate');
const complement = require('ramda/src/complement');
const Element = require('./Element');
const ArraySlice = require('../ArraySlice');

Expand Down Expand Up @@ -118,7 +118,7 @@ class ArrayElement extends Element {
* @returns {ArraySlice}
*/
reject(callback, thisArg) {
return this.filter(negate(callback), thisArg);
return this.filter(complement(callback), thisArg);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/primitives/Element.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const isEqual = require('lodash/isEqual');
const equals = require('ramda/src/equals');
const KeyValuePair = require('../KeyValuePair');
const ArraySlice = require('../ArraySlice.js');

Expand Down Expand Up @@ -219,7 +219,7 @@ class Element {
}

equals(value) {
return isEqual(this.toValue(), value);
return equals(this.toValue(), value);
}

getMetaProperty(name, value) {
Expand Down
9 changes: 4 additions & 5 deletions lib/primitives/ObjectElement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const negate = require('lodash/negate');
const isObject = require('lodash/isObject');

const complement = require('ramda/src/complement');
const is = require('ramda/src/is');
const ArrayElement = require('./ArrayElement');
const MemberElement = require('./MemberElement');
const ObjectSlice = require('../ObjectSlice');
Expand Down Expand Up @@ -90,7 +89,7 @@ class ObjectElement extends ArrayElement {
* If an object is given, each key is set to its respective value
*/
set(keyOrObject, value) {
if (isObject(keyOrObject)) {
if (is(Object, keyOrObject)) {
Object.keys(keyOrObject).forEach((objectKey) => {
this.set(objectKey, keyOrObject[objectKey]);
});
Expand Down Expand Up @@ -190,7 +189,7 @@ class ObjectElement extends ArrayElement {
* @memberof ObjectElement.prototype
*/
reject(callback, thisArg) {
return this.filter(negate(callback), thisArg);
return this.filter(complement(callback), thisArg);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"sinon": "^7.2.4"
},
"dependencies": {
"lodash": "^4.15.0"
"ramda": "^0.26.1"
},
"engines": {
"node": ">=6"
Expand Down