amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.14k stars 1.17k forks source link

Converting Object to Arrays #382

Open imerkle opened 7 years ago

imerkle commented 7 years ago

I was trying to use Arrays as data for Gun. Since they dont support arrays i made a simple function to convert it.

https://gist.github.com/dsslimshaddy/9ea160838c844473a5f3736d50d1fb19

If there is any other way to do the following please recommend.

//this kind of format
    let lists = [{
              title: "FrontEnd",
              list: ["Javascript","Elm"]
            },
            {
              title: "BackEnd",
              list: ["Node","Go"]
            }];  
amark commented 7 years ago

Nice! Thanks, we should get this published as an extension and I'll link to it on the README! Thanks for jumping in and helping out.

Note: it is important to understand that arrays have different concurrency implications that are not preserved with gun or this (which is why gun errors, I don't want to mislead users about how their data is being stored), but as you have just done, it is easy to approximate - but I just want to provide ample/sufficient warning about behavior.

If you need more strongly guaranteed arrays, I recommend using a linked list to preserve ordering. Or using .set if you need table / collection like behavior. However this is perfect for finite arrays that have fixed indices. And many people will find it refreshing to use!

buckle2000 commented 7 years ago

This cannot handle circular graph