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

focusAtom and Setter optic #7

Open
lukeKonopka opened this issue Apr 18, 2023 · 2 comments
Open

focusAtom and Setter optic #7

lukeKonopka opened this issue Apr 18, 2023 · 2 comments

Comments

@lukeKonopka
Copy link

It would be nice if focusAtom worked with Setter type from optics-ts.
Using it with focusAtom should produce a write-only atom.
One possible use case would be to allow for appending to an array inside an atom, like this:

const stringArrayAtom = atom<string[]>([]);

const appendToArrayAtom = focusAtom(stringArrayAtom, (optic) => optic.appendTo()); // WritableAtom<null, [SetStateAction<string>], void>

As far as I can tell, it should work with the current implementation, we only need to change typing for focusAtom to accept Setter optic and return corresponding WritableAtom.

If it sounds like something worth supporting, I can create a PR with that change.

@dai-shi
Copy link
Member

dai-shi commented Apr 18, 2023

It sounds worth supporting to me.
cc: @merisbahti @arjunvegda

@arjunvegda
Copy link
Member

+1 That would be a good addition to the library!

Would Getters be a good addition, too, or should we prefer read-only atoms instead?

ikeyan added a commit to ikeyan/jotai-optics that referenced this issue Jul 16, 2024
ikeyan added a commit to ikeyan/jotai-optics that referenced this issue Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants