-
Notifications
You must be signed in to change notification settings - Fork 5
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
Filtering atoms in todo example #45
Comments
What I tried the first time, was to use Another idea, would be to create an atom which represents the same thing ( I guess I'm wondering, what do you feel is more idiomatic? Is there a good optics, or |
I come with an FRP background so for me, filtering an Atom would mean skipping a value that doesn't match a predicate. So, from the user's point of view it means that the Atom should "freeze" to its previous value (the last one that matched the predicate). In the Lonna FRP library used in Harmaja, you can filter atoms, as seen in this test. This sort of filtering is employed in the Harmaja ListView to ensure that item views are not rendered after the particular item has been removed from the list atom. Then again, you seem to want to filter out unwanted values from an atom that holds an array of values, that's of course a With Harmaja, you can pick wither Atoms+Lenses or Actions+Reducer and for some cases, actions+reducer feel more suitable. When using actions+reducer, you don't have to solve that complex problem but can compose your UI from view components that don't have to worry about how mutations are implemented - just dispatch actions for the reducer. Or you can also combine the two approaches to get the best of both worlds. And these solutions are not really Harmaja-specific, you could very well pick the Lonna library for Atoms and all other FRP constructs (event streams, properties, buses...) and write a few React hooks to use them with React. |
Oh, sorry @merisbahti. When we discussed in the optics-ts issue I didn't pay attention to what the actual problem was you were trying to solve 🙄 I've built something similar to calmm.js in TypeScript here: https://codesandbox.io/s/goofy-sun-j1zoz. Have a look at It basically uses the If a prism stops matching, e.g. when the prism focuses on the last element of an array and something is removed from the array, the corresponding atom is "deactivated", i.e. it stops subscribing to its parent. The Dunno if this stuff helps you, but I hope you get some ideas at least! |
Hello!
I was recently made aware of this library, and I felt really amazed, it feels like someone is thinking like me out there.
I've made a similar library, inspired by
jotai
and usesoptics-ts
, but specifically forreact
, called klyva.I have a very similar example to you, where I implement todo-application, and I was recently struggling with implementing
filter
.Please note that, in
klyva
, to getArray<Atom<Element>>
from anAtom<Array<Element>>
, one uses a function called useAtomSlice. This is very similar, I believe, to what ListView accomplishes (both even make them removable):So what I did, was implement a value, which represents if the atom at
index
should be filtered. Its name is shouldBeFilteredAtIndex.Given
shouldBeFilteredAtIndex
, one can filter theArray<Atom<...>>
here before rendering them out.How would you go about implementing "filter" of atoms, using
ListView
component? I see no way to filter it based on its value.The text was updated successfully, but these errors were encountered: