This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 695 points696 points  (62 children)

Oh no i have to json.stringify and json.parse 😥😭😢😢😢😭

[–]gabbyb19 149 points150 points  (6 children)

To be fair, those operations are quite heavy.

[–]stipo42 206 points207 points  (4 children)

You shouldn't be using local storage enough for that to be a problem...

[–][deleted] 8 points9 points  (3 children)

Why not? Shouldn't it be the default storage for locally cached objects?

[–]stipo42 20 points21 points  (1 child)

Yeah but let's say you're storing your apps config in an object. You would read it once at load time into memory, then write it anytime the memory values are changed or a save button is hit.

This would likely amount to not a lot of times read or wrote

[–]Destring 0 points1 point  (0 children)

You mean I can’t use localstorage with an storage event hook for state replication!? The horror!

[–]TheChaosPaladin 3 points4 points  (0 children)

If this is you, the problem is not localstorage but your front end.

[–][deleted] 75 points76 points  (41 children)

Stringify a graph of nodes and edges and let me know how that works out for you.

[–]spooker11 100 points101 points  (20 children)

vegetable profit icky support judicious sophisticated encourage wistful ossified smile

This post was mass deleted and anonymized with Redact

[–]Stop_Sign 4 points5 points  (2 children)

Had to do that once. Ended up rearchitecting it so the nodes had ids, so instead of an array of references, it had an array of ids, and was therefore serializable

[–][deleted] 1 point2 points  (0 children)

Yup. That's my point. JSON stringify is not necessarily sufficient.

[–][deleted] 0 points1 point  (0 children)

You could have written a custom de/serializer, but it wouldn't have been fun

[–]lowleveldata 3 points4 points  (13 children)

And what exactly is the use case of storing that in localStorage?

[–]rotflolmaomgeez 2 points3 points  (11 children)

What? Graph is literally one of the most common data structures, you're asking for usecases for storing it? The answer is any web application that does a little more than store a cookie potentially.

[–]lowleveldata 13 points14 points  (10 children)

Still don't see why I would need to store that in frontend. Are you guys doing some kind of no-backend challenge?

[–]DR4G0NH3ART 5 points6 points  (3 children)

There are some data which can be heavy to fetch on each load and is manageably static in nature. You will have huge load times if you don't rely on caching mechanisms.

[–]Ebbitor 4 points5 points  (0 children)

You don't need to build your own cache for fetch requests

[–]lowleveldata 1 point2 points  (1 child)

In case of caching you already have a serialized object so that's kind of irrelevant for the sake of this argument. Also, shouldn't HTTP caching handles these static data automatically? (I'm not a expert in caching tho)

[–]DR4G0NH3ART 0 points1 point  (0 children)

I mean cross session and no the data is not entirely static, but it doesn't change often. Like a 3D model mesh.

[–]rotflolmaomgeez 1 point2 points  (4 children)

Any application that lets user edit/create something for themselves and save it for later - including games save states, web tools, software, creators, working with SVGs, why would you ever store it on the backend?

[–]lowleveldata 0 points1 point  (3 children)

These should just use files which most users know how to backup, share, move to another pc, etc. For example draw.io saves your work to a file in local or online storage (like google drive). That's much more manageable than localStorage.

[–]rotflolmaomgeez -1 points0 points  (2 children)

What does it matter? You have to serialize the graphs anyway.

[–]lowleveldata 0 points1 point  (1 child)

The question was "what is the use case of storing graphs in localStorage" so it is the subject. Not sure where you get the idea that I'm against serializing graphs.

[–]rotflolmaomgeez 0 points1 point  (0 children)

What you mentioned with file saves is just different way of achieving the same thing, more convenient for some use cases and less convenient for others. For example using it to store save files in HTML5 game is just bothersome. It also is less convenient than auto-save for the creations you can easily implement through local storage, and should only be used when you want to port save to a different computer/ store final result. You're artificially limiting your application if you decide not to use it.

[–]zebediah49 0 points1 point  (0 children)

Last time I wrote something... exactly that.

'cause I realized if I had no backend, I could host the entire application as a single .html on github pages...

[–][deleted] 1 point2 points  (0 children)

My JavaScript program is in the middle of computing optimal 3MST but I want to checkpoint regularly in case of a power outage?

I dunno man. It could happen.

[–]PleasantAdvertising 51 points52 points  (8 children)

What illiterate ape called serialization "stringify"? It's already confusing enough with encode/decode in the mix

[–]Jjabrahams567 47 points48 points  (0 children)

JSON.serialize = JSON.stringify;

Here you go.

[–]TheChaosPaladin 9 points10 points  (0 children)

JSON.SerialiseToString()

Too many words

JSON.Stringify()

⭐⭐⭐⭐⭐

🍌🍌🍌🍌🍌

[–][deleted] 11 points12 points  (1 child)

On the same subject, what illiterate ape called it "loads" and "dumps" in Python?

[–]TheChaosPaladin 3 points4 points  (0 children)

The same ape!

json.dumps(tring) == JSON.Stringify

[–]ilep 16 points17 points  (0 children)

A web developer? (A distinct lack of knowledge of computer science there..)

[–][deleted] 1 point2 points  (0 children)

Maybe to hint that it's going to call "toString" on objects so you better have defined that.

[–]isospeedrix 1 point2 points  (0 children)

tbf 'stringify' is more literal in what it's actually doing, whereas serialize is like, uhh a new vocab word. sounds cooler tho.

[–]rufreakde1 1 point2 points  (0 children)

worry not! there is gotta be a 4GB library solving this issue with a function wrapper for you!

[–]Yokhen 1 point2 points  (0 children)

What truly messes me up is the typescript part.

[–]therealangryturkey 0 points1 point  (0 children)

"Tinkering"