diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e88f8e5..e68d9f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # CHANGELOG +## 0.3.3 + +- You can now link nodes natively, `gun.get('mark').path('owner').put(gun.get('cat'))`! +- Sets (or tables, collections, lists) are now easily done with `gun.get('users').set(gun.get('person/mark'))`. + +## 0.3.2 + +Bug fixes. + +## 0.3.1 + +Bug fixes. + ## 0.3 Migration Guide! Migrate by changing `.attach(` to `.wsp(` on your server if you have one with gun. Change `.set()` (empty call) to `` (aka delete it), and change `.set($DATA)` (where you call set with something) to `.path('I' + Date.now() + 'R' + Gun.text.random(5)).put($DATA)`. If you have NodeJS style callbacks in your `.get` (which documentation previously recommended that you shouldn't) they previous took `err, graph` and now they take `err, node` (which means now using callback style is fine to use). Inside of `.not()` no longer use `return` or `this`, instead (probably) use `gun` and no `return`. If you are a module developer, use `opt.wire` now instead of `opt.hooks` and message Mark since he needs to talk to you since the wire protocol has changed. diff --git a/gun.js b/gun.js index 524f36cc..e6c422c0 100644 --- a/gun.js +++ b/gun.js @@ -961,6 +961,18 @@ return chain; } + Gun.chain.set = function(item, cb, opt){ + var gun = this, ctx = {}; + if(!Gun.is(item)){ return cb.call(gun, {err: Gun.log('Set only supports node references currently!')}), gun } + item.val(function(node){ + if(ctx.done){ return } ctx.done = true; + var put = {}, soul = Gun.is.node.soul(node); + if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) } + gun.put(Gun.obj.put(put, soul, Gun.is.rel.ify(soul)), cb, opt); + }) + return gun; + } + Gun.chain.init = function(cb, opt){ var gun = this; gun._.at('null').event(function(at){ diff --git a/test/common.js b/test/common.js index 7d089694..7306f26d 100644 --- a/test/common.js +++ b/test/common.js @@ -3720,6 +3720,51 @@ describe('Gun', function(){ }); },100); }); + + it.skip("gun path via gun path", function(done){ // TODO: Future feature? + var gun = Gun(); + var book = gun.put({ name: 'Potato Cooking' }); + var author = gun.put({ name: 'Bob Bobson' }); + author.path(book.path('name')).put(book); + }); + + it("gun set", function(done){ + var gun = Gun(); + var users = gun.get('users'); + var alice = gun.put({name: 'alice', birth: Math.random()}).key('person/alice'); + var bob = gun.put({name: 'bob', birth: Math.random()}).key('person/bob'); + var carl = gun.put({name: 'carl', birth: Math.random()}).key('person/carl'); + var dave = gun.put({name: 'dave', birth: Math.random()}).key('person/dave'); + + users.set(alice).set(bob).set(carl).set(dave); + + alice.path('friends').set(bob).set(carl); + bob.path('friends').set(alice); + dave.path('friends').set(alice).set(carl); + + var team = gun.get('team/lions').put({name: "Lions"}); + team.path('members').set(alice).set(bob); + + alice.path('team').put(team); + bob.path('team').put(team); + + dave.path('friends').map().path('team.members').map().val(function(member){ + //console.log("Dave's friend is on a team that has", member.name, "on it."); + if('alice' === member.name){ + done.alice = true; + } else + if('bob' === member.name){ + done.bob = true; + } else { + expect(member).to.not.be.ok(); + } + if(done.alice && done.bob){ + setTimeout(function(){ + done(); + },10); + } + }); + }); }); describe('Streams', function(){