Skip to content

Commit

Permalink
Add defaultsOn (#29)
Browse files Browse the repository at this point in the history
* Add defaultsOn

* Get these trailing spaces out of Travis' face 👋
  • Loading branch information
frozegnome authored and sadasant committed Feb 17, 2017
1 parent 7941944 commit 30ff37a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.7.0
- Add `defaultsOn`

# 1.6.0
- Add `extendOn`

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ These methods provide alternative orderings that are sometimes more convenient.
The idea of `In` methods is to name them by convention, so when ever you need a method that actually takes the collection first (e.g. a `get` where the data is static but the field is dynamic), you can just add `In` to the end (such as `getIn` which takes the object first)

### `On`s (Immutable False)
`extendOn`
`extendOn`, `defaultsOn`
lodash/fp likes to keep things pure, but sometimes JS can get pretty dirty.
These methods are alternatives for working with data that--for whatever the use case is--needs to be mutable
Any methods that interact with mutable data will use the `On` convention (as it is some action occuring `On` some data)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "futil-js",
"version": "1.6.0",
"version": "1.7.0",
"description": "F(unctional) util(ities). Resistance is futile.",
"main": "lib/futil-js.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const includesIn = _.includes.convert({ rearg: false })
// Mutables
// ----------
export const extendOn = _.extend.convert({ immutable: false })
export const defaultsOn = _.defaults.convert({ immutable: false })

// This reduce based version is easier to maintain but requires calling `F.inversions.fn` instead of `F.fn`
let inversionList = ['get', 'pick', 'includes'];
Expand Down
File renamed without changes.
18 changes: 15 additions & 3 deletions test/mutables.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@ const expect = chai.expect

describe('Mutable FP Functions', function() {
it('extendOn', function() {
let expected = f.extendOn({
expect(f.extendOn({
a: 1
}, {
a: 2,
b: 3,
c: 4
})).to.deep.equal({
a: 2,
b: 3,
c: 4
})

expect(expected).to.deep.equal({
})

it('defaultsOn', function() {
expect(f.defaultsOn({
a: 2,
b: 3,
c: 4
}, {
a: 1
})).to.deep.equal({
a: 1,
b: 3,
c: 4
})
})
})

0 comments on commit 30ff37a

Please sign in to comment.