Replies: 2 comments · 2 replies
-
|
We use a hash in the website demo, actually, but it's just gzip+base64 and not deterministic to my knowledge. Code is here. Its only real purpose is to reduce the size of the style library links and the permalink. I think I tried to debounce it at some point a while back, but gave up after running into issues trying to get it to work within the Docusaurus paradigm. A fast, deterministic hash method certainly sounds useful in this space. My first inclination is to agree that it might be out of scope for RQB, but I'd be willing to entertain suggestions. If we didn't have to add a dependency (although I would consider vendoring something, maybe that JS port of xxhash?), what sort of API would you expect from this library? Would it integrate with the |
Beta Was this translation helpful? Give feedback.
-
|
Having thought about it more, I'm leaning towards utility. You can basically call getHash(thisIsMyQueryBuilderState) from anywhere you have access to the RQB state, no problem, and generally someone's usage of a function like that, would be pretty decoupled from the QueryBuilder itself. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd love to see an integrated 'hash' for the current query.
This might be beyond the scope of the query builder, so I'm not sure it fits within the package, but I've found it very useful, at least when integrating the builder with tanstack query and other tools.
The way I approach this is I take the state of the builder, stringify the JSON deterministically and use xxhash (reliable and very fast, especially considering it's characteristics) on that.
The benefit here is that, if you are relying on tanstack query to for example, send the query to parse to the backend or provide results, you can utilize this hash as part of the query key to actually trigger that update / fetch.
In my use case (and probably for most situations) I've debounced the hashing function. The hashing and everything is extremely efficient, but it's relatively pointless to spam a user's typing, when you're dealing with a query builder that offers complex filtering and is likely not targeting your more efficient autocomplete endpoints / indexes.
https://github.com/Cyan4973/xxHash
https://github.com/Daninet/hash-wasm (there might be better WASM ones? I don't really know how much it matters here)
Beta Was this translation helpful? Give feedback.
All reactions