diff --git a/README.md b/README.md index e9f0986e..e7baba63 100644 --- a/README.md +++ b/README.md @@ -558,27 +558,27 @@ A lens can be any of these formats: `({ get, set })` An object with a `get` function and `set` function. Found in: MobX "boxed observables" -Example Usage: `F.flip({ get, set })` +Example Usage: `F.flips({ get, set })` `([value, setter])` An array of the `value` and a `setter` function to change it. Found in: React's useState hook -Example Usage: `F.flip([value, setter])` +Example Usage: `F.flips([value, setter])` `(lookup, object)` A lookup path and object pair e.g. ('key', object). The lookup path is anything you can pass to `_.get` (so nested paths with `.` or as an array are supported) Found in: MobX observable objects, native JS objects -Example Usage: `F.flip(lookup, object)` +Example Usage: `F.flips(lookup, object)` `(x => {})` A function which returns the value when called with no arguments and sets it when called with one. Found in: Knockout observables, jQuery plugin APIs -Example Usage: `F.flip(x => {})` +Example Usage: `F.flips(x => {})` `(getter, setter)` A getter and setter pair. Found in: Anywhere you have a getter and setter function -Example Usage: `F.flip(getter, setter)` +Example Usage: `F.flips(getter, setter)` > Note: Setter methods are generally mutable (unlike Ramda's lenses, for example). @@ -602,7 +602,7 @@ Creates a function that will set a lens with the provided value #### setsWith Takes an iteratee and lens and creates a function that will set a lens with the result of calling the iteratee with the provided value -#### flip +#### flips Takes a lens and negates its value #### on diff --git a/src/lens.js b/src/lens.js index 4a5ed506..de659532 100644 --- a/src/lens.js +++ b/src/lens.js @@ -71,7 +71,7 @@ export let sets = _.curryN(2, (val, ...lens) => () => set(val, ...lens)) export let setsWith = _.curry((f, ...lens) => x => set(_.iteratee(f)(x), ...lens) ) -export let flip = (...lens) => () => set(!view(...lens), ...lens) +export let flips = (...lens) => () => set(!view(...lens), ...lens) export let on = sets(true) export let off = sets(false) diff --git a/test/lens.spec.js b/test/lens.spec.js index fb12aace..7cac4eb6 100644 --- a/test/lens.spec.js +++ b/test/lens.spec.js @@ -116,12 +116,12 @@ describe('Lens Functions', () => { setter(5) expect(object.a).to.equal(10) }) - it('flip', () => { + it('flips', () => { let object = { a: 1, } let l = F.lensOf(object) - F.flip(l.a)() + F.flips(l.a)() expect(object.a).to.equal(false) }) it('on', () => { @@ -172,11 +172,11 @@ describe('Lens Functions', () => { F.sets(5, 'a', x)() expect(x.a).to.equal(5) }) - it('flip', () => { + it('flips', () => { let object = { a: 1, } - F.flip('a', object)() + F.flips('a', object)() expect(object.a).to.equal(false) }) it('on', () => { @@ -208,7 +208,7 @@ describe('Lens Functions', () => { expect(lens[0]).to.be.true F.off(lens)() expect(lens[0]).to.be.false - F.flip(lens)() + F.flips(lens)() expect(lens[0]).to.be.true }) it('functionPairLens', () => { @@ -223,7 +223,7 @@ describe('Lens Functions', () => { expect(object.a).to.be.true F.off(get, set)() expect(object.a).to.be.false - F.flip(get, set)() + F.flips(get, set)() expect(object.a).to.be.true }) })