Skip to content

Commit

Permalink
feat(lens): migrate to new signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyzu authored and raveclassic committed Jan 14, 2022
1 parent 1005889 commit fa6e5d1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/lens/src/lensed-atom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Atom, Env, atom } from '@frp-ts/core'
import { Atom, Env, atom, interopObservable } from '@frp-ts/core'

export interface Lens<S, A> {
readonly get: (s: S) => A
Expand All @@ -15,11 +15,13 @@ export const newLensedAtom = (env: Env): (<A>(initial: A) => LensedAtom<A>) => {
}

export const toLensedAtom = <A>(atom: Atom<A>): LensedAtom<A> => {
const { set, get, subscribe, modify } = atom
const { set, get, subscribe } = atom

const view = <B>(lens: Lens<A, B>): LensedAtom<B> => {
const lensedGet = () => lens.get(get())
const lensedSet = (b: B) => set(lens.set(b)(get()))
const interop = () => interopObservable.newInteropObservable(subscribe, lensedGet)

return {
get: lensedGet,
set: lensedSet,
Expand All @@ -32,14 +34,12 @@ export const toLensedAtom = <A>(atom: Atom<A>): LensedAtom<A> => {
}
lensedSet(value)
},
[interopObservable.observableSymbol]: interop,
}
}

return {
set,
get,
subscribe,
modify,
...atom,
view,
}
}
Expand Down

0 comments on commit fa6e5d1

Please sign in to comment.