intendednull / yewdux

Ergonomic state management for Yew applications
https://intendednull.github.io/yewdux/
Apache License 2.0
319 stars 31 forks source link

IndexedDB agent #70

Open TiemenSch opened 9 months ago

TiemenSch commented 9 months ago

I went ahead and took the plunge for an IndexedDB worker crate using yew-agent and also added a small example.

However, something is off with deserialization and I can't seem to find it.

TiemenSch commented 9 months ago

Well, deserialization was just a simple mistake to fix.

The Cargo.toml changes are related to some weird Hook impl errors on the examples. Not sure what is going on there.

The current basis is more or less a generic IndexedDB worker I drummed up. I could even put that in it's own crate, because it isn't really yewdux specific at all. I'm kind of on the fence between the current BTreeMap for put actions and a more generic FIFO vector approach that would work through all messages instead of the latest one per pointer. I think the Map approach makes sense for Yewdux' serialization since you wouldn't want to do any redundant PUT cycles.

However, the part that is glaringly missing is a more sensible way for Store initialization and a dedicated listener for the IndexedDB way of things. The example's dummy component method is a tad bit hacky (:

What do you think?

intendednull commented 9 months ago

Haven't had time yet for a thorough review, but I like the idea! Maybe it would be possible to connect a store to the db worker, so it will automatically sync changes.

Will get back with a more detailed response when I have some time to dive in. Thanks for your contribution!

TiemenSch commented 9 months ago

I've been toying around with the idea to generalize the WebWorker part in a separate crate (MIT/Apache) this week.

I.e. extracting the job shop/queue part for different strategies.

I'll link to it when I get to it, but depending on what you prefer for yewdux you're free to copy/use and adapt the code directly instead of adding a dependency.

intendednull commented 9 months ago

That might be better tbh. We can always add an adapter here, but I think DB management itself might be stretching this projects scope