Skip to content
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

Lens funtion consistency #304

Open
wants to merge 3 commits 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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions test/lens.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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
})
})
Expand Down