choojs / choo

:steam_locomotive::train: - sturdy 4kb frontend framework
https://choo.io/
MIT License
6.78k stars 595 forks source link

Choo Offline First #620

Open sholtomaud opened 6 years ago

sholtomaud commented 6 years ago

Question

Loved the new documentation about Forms, but notice that the pattern uses fetch to POST data and then nothing more.

What is best practice for a choo offline first approach?

I was looking at Gunjs for database sync, however it is a bit green, and a very large library. Kind of an anti-pattern when compared to choo.

yoshuawuyts commented 6 years ago

@shotlom heya, good question!

So this is a really tricky question, with no good answer. What you're asking for is how to eventually sync up values, and possibly roll back the results. This means doing some form of action that stores values inside IndexedDB until it's ready to be sent.

Generally my advice for this would be to not go down that path. Disable input fields if offline, and save yourself the trouble. If that's not an option, however, you can look into "syncable" databases like couchdb/pouchdb, and the newer hyperdb. None of which are going to be small, but that's the cost inherent to the problem.

Hope that answers your question!

sholtomaud commented 6 years ago

Thanks @yoshuawuyts for the response.

I'm not sure if you've looked into Gun.js.db. It's an interesting approach inspired by couchdb. As you say, it's not small in size so rubs up against the choo motivation.

Enabled input fields is important for some use cases so ... what to do? Perhaps this issue can be a collection point for future options.

sholtomaud commented 6 years ago

It would good to get your thoughts @yoshuawuyts on Geir's experiments for example with choo and gun.

https://github.com/zrrrzzt/choo-gun-test

yoshuawuyts commented 6 years ago

@shotlom looks fun!