Live data from Hacker News

How to store your app's entire state in the url

scottantipa.com

411–416 of 416 posts

Re: How to store your app's entire state in the url

#411

Last November I had covid and during that time I wrote a little pastebin that runs in the browser, compresses the paste data with Brotli, and puts it in the URL. It has line numbers, file naming, and syntax highlighting so it's feature complete for my own use. Here's a demo, but beware, the URLs are loooong: https://nicd.gitlab.io/t/#NhfW?Qm3F?6-&22c&CQZXuP+Aej5OXzXk7... I find it interesting to sometimes play around…

> The maximum URL size is 2048 FYI, this is almost entirely untrue. Maybe for some old versions of IE, but modern browsers can handle extremely long URIs

Yep, I rechecked it and seems Chrome/Fx/Safari all support at least 32k. I replied in another comment I'm considering a checkbox to allow even longer URLs, though, I don't know who would want to paste them for others to read. :D

Re: How to store your app's entire state in the url

#412

Earlier quoted context omitted.

Agreed. However they could still simplify the urls a ton by including only non-default parameters, and still achieve the same thing.

Everything in chart is customizable, so no, its not possible to achieve the same thing in the way you are saying

Yes, but anything that hasn't been customized doesn't need to be included in the URL, so most URLs will be much shorter by only including non-default values.

Re: How to store your app's entire state in the url

#413
post #337

Earlier quoted context omitted.

Well yeah that's a major reason why most programmers hate LISP syntax. It uses a parentheses for everything even though every keyboard has round, square, angle and curly braces.

I somehow doubt it. I tutored quite a few people of all ages who started to learn programming, mostly C, C++ and Java - they all initially have been mostly confused by the different kinds of brackets. They quickly understood where the brackets go (scopes/blocks, function calls, array declarations and access, etc.), but took some time to internalize which bracket type is used in which context. I suspect the main reaso…

Like most of the verbosity in those languages it benefits the reader more than the writer.

Re: How to store your app's entire state in the url

#414

About 6 years ago I had to do this on a project. We had charts with a lot of options and we wanted them to be bookmarkable and shared between colleagues. We started with base64, soon moved to a custom encoding with version support https://github.com/ananthakumaran/u

I learned about your library because the harmopark.app site uses and credits it. I plan to use it in a music app I'm developing.

I saw someone forked it and removed the lodash dependency / minor refactoring https://github.com/ananthakumaran/u/compare/master...j-te:u:...

Re: How to store your app's entire state in the url

#415

This is a useful idea when you've got complex nested state. The problem is changing any particular part of the state is non-trivial. I ended up making `friendly-serializer`[0] to "make objects more accessible in urls." The idea is that instead of a base64 string, you get something that is much easier to edit in the url bar: > name=John%20Doe&age=42&address.street=123%20Main%20Street&address.city=Anytown&address.state…

You can have multiple values under the same search parameter. For example, ?a=b&a=c&a=d, which would be the array [b, c, d]. Including the index key seems redundant. The native URLSearchParams browser interface even supports this with the getAll method. https://developer.mozilla.org/en-US/docs/Web/API/URLSearchPa...

Great point! Added to my TODOs

Re: How to store your app's entire state in the url

#416

This is a useful idea when you've got complex nested state. The problem is changing any particular part of the state is non-trivial. I ended up making `friendly-serializer`[0] to "make objects more accessible in urls." The idea is that instead of a base64 string, you get something that is much easier to edit in the url bar: > name=John%20Doe&age=42&address.street=123%20Main%20Street&address.city=Anytown&address.state…

I found the other package: https://www.npmjs.com/package/friendly-querystring (noting mostly for my own sake)
Post reply on HN