-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Support structural equality for keys #510
Comments
Hello @pbadenski. Do you have a code example of what this would entail or describe a use case you would have for it? The tree does not compute hash codes for the stored information for performance reasons but there may be some tricks regarding the tree transactions in some configurations. |
I realised that this might require massive changes to baobab... possibly integrating it more closely with immutablejs as no builtin JS structures support structural equality for keys. Use case - we currently use rxjs to react to changes of entries in large collections & I was thinking if I could use baobab instead as a more lightweight (& potentially more efficient) solution. We use ImmutableJS collections which support structural equality and that allow us to use composite object keys. Here's a rough example:
|
I am not sure I fully understand your use case here @pbadenski. But a decent workaround for composite key has always been scalar coercion. Like |
Thanks, we've actually been using scalar coercion, but changed it a while back because of the complexity and performance costs. Still - I like your use of I've actually found that immutablejs does something similar with https://github.com/redbadger/immutable-cursor - however only allows to register watchers at creation - which is not ideal... I'm not sure about the application functional lenses approach in terms of my suggestion. I suppose - in theoretical sense - if it allowed to store arbitrary data structures & allow implementing a baobab compatible interface? So say - if I want to store Immutable.JS Map in baobab - how would that work? How would that be compatible with watchers? |
Yes it would be a little like this.
For this to work I would need you to tell my utilities how to get/traverse and set at a given path. Which you can easily specify through functions and interfacing with ImmutableJS in this way for instance wouldn't be too complicated to write.
My watchers, and this is as much a boon as a curse performance-wise, never rely on equality but only on path comparison and matching. Which make this compatible with any system such as Immutable for instance, as soon as you guarantee you will only be using baobab setters/getters and such. If you don't, I cannot make my watchers etc. work of course but this is already the case in the current state of the library and this is why I tell users not to mutate the tree by themselves to avoid this. |
Looks like it could be really interesting and powerful 😄 I'm excited! |
And did you take a look at recoiljs? In a way it has a similar approach to what I describe here (apart from the annoying fact that you cannot act on its atoms outside of a react component). |
I haven't yet, I might for inspiration - I need this functionality outside of React :) |
Would it be possible, similar to Immutable.JS (or Java..), have support for keys based on structural equality (ie. hashCode, equals)?
The text was updated successfully, but these errors were encountered: