mirror of
https://github.com/amark/gun.git
synced 2025-06-25 07:22:32 +00:00
set / table / list / collections !
This commit is contained in:
parent
b7a335dd3b
commit
a05cf84315
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,5 +1,18 @@
|
|||||||
# CHANGELOG
|
# 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
|
## 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.
|
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.
|
||||||
|
12
gun.js
12
gun.js
@ -961,6 +961,18 @@
|
|||||||
return chain;
|
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){
|
Gun.chain.init = function(cb, opt){
|
||||||
var gun = this;
|
var gun = this;
|
||||||
gun._.at('null').event(function(at){
|
gun._.at('null').event(function(at){
|
||||||
|
@ -3720,6 +3720,51 @@ describe('Gun', function(){
|
|||||||
});
|
});
|
||||||
},100);
|
},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(){
|
describe('Streams', function(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user