Install
You have to installoptics-ts and jotai-optics to use this feature.
focusAtom
focusAtom creates a new atom, based on the focus that you pass to it. This creates a derived atom that will focus on the specified part of the atom,
and when the derived atom is updated, the derivee is notified of the update, and the equivalent update is done on the derivee.
See this:
PrimitiveAtom<{a: number}>, which has a getter and a setter, and then used focusAtom to zoom in on the a-property of
the baseAtom, and got a PrimitiveAtom<number>. What is noteworthy here is that this derivedAtom is not only a getter, it is also a setter. If derivedAtom is updated, then equivalent update is done on the baseAtom.
The example below is simple, but it’s a starting point. focusAtom supports many kinds of optics, including Lens, Prism, Isomorphism.
To see more advanced optics, please see the example at: https://github.com/akheron/optics-ts