gun icon indicating copy to clipboard operation
gun copied to clipboard

How to traverse path until it's end

Open mstimvol opened this issue 5 years ago • 1 comments

I'm pretty new to GUN and it's really awesome but I've a question regarding traversing. Assume I've the following structure:

gun.get('people').get('Dave').put({
  someData: 0
})

gun.get('people').get('Charlie').put({
  someData: 1
}).get('knows').put(gun.get('people').get('Dave'))

gun.get('people').get('Bob').put({
  someData: 2
}).get('knows').put(gun.get('people').get('Charlie'))

gun.get('people').get('Alice').put({
  someData: 3
}).get('knows').put(gun.get('people').get('Bob'))

//
// No one knows Eve but she's part of the "people" collection...
gun.get('people').get('Eve').put({
  someData: 4
})

Now, I want start at "Alice" and traverse the "knows"-path so that I finally get "Dave" (which doesn't know anyone else). Here's my current query:

gun.get('people').get('Alice').get('knows').get('knows').get('knows').once(v => console.log(v))

My problem is that I don't know how "deep" my graph is. So I'm looking for a solution like "start at 'Alice' and traverse the 'knows' path until it's end, so there's no 'knows' connection anymore.". Sure, I can do this using a while-loop, but maybe there's a better/other/builtin-solution?

mstimvol avatar Dec 25 '20 13:12 mstimvol

@mstimvol hey looks like you asked this right before Christmas & stuff. Mind jumping on http://chat.gun.eco for Qs? You'll get much faster replies. :)

amark avatar Jan 23 '21 07:01 amark