Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
jotai-optics
Advanced tools
## Background It's easy to "combine" two atoms, but how do we split an atom?
It's easy to "combine" two atoms, but how do we split an atom?
The answer is optics.
This is based on this issue: https://github.com/pmndrs/jotai/issues/44
We've got Prisms, Lenses, Isos, Traversals and of course Equivalences.
import { atom } from 'jotai'
import { focus } from 'jotai-optics'
const bigAtom = atom({ a: 0, b: 5 })
const focusAAtom = focus(bigAtom, (optic) => optic.prop('a'))
const focusBAtom = focus(bigAtom, (optic) => optic.prop('b'))
For when you have something of type Atom<Array<TodoItem>>
but you would like to have Array<Atom<TodoItem>>
, so for example, say that your TaskItem
component looks like this:
const TaskItem = ({ atom }: { atom: RWAtom<TodoItem> }) => {
const [value, onChange] = useAtom(atom)
const toggle = () => {
onChange(value => {
return { ...value, checked: !value.checked }
})
}
return (
<li data-testid={value.task}>
{value.task}
<input
data-testid={`${value.task}-checkbox`}
type="checkbox"
checked={value.checked || false}
onChange={toggle}
/>
</li>
)
}
but the parent, TaskList
only has an Atom<Array<TodoItem>>
in it, that's when useAtomArrayFamily
is useful:
const TaskList = ({ todoItems }: { todoItems: RWAtom<Array<TodoItem>> }) => {
const atoms = useAtomArrayFamily(todoItems)
return (
<>
{atoms.map(([todoItem], index) => (
<TaskItem key={index} atom={todoItem} />
))}
</>
)
}
FAQs
The npm package jotai-optics receives a total of 183,295 weekly downloads. As such, jotai-optics popularity was classified as popular.
We found that jotai-optics demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.