mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
map
This commit is contained in:
parent
f8e4196dc9
commit
45122b5d9a
@ -1,5 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.6
|
||||
- 0.8
|
||||
- 0.10
|
||||
- 0.11
|
13
gun.js
13
gun.js
@ -520,11 +520,13 @@
|
||||
return gun;
|
||||
}
|
||||
Chain.map = function(cb, opt){
|
||||
var gun = this;
|
||||
opt = (Gun.obj.is(opt)? opt : (opt? {node: true} : {})); // TODO: BUG: inverse the default here.
|
||||
gun.val(function(val){
|
||||
cb = cb || function(){};
|
||||
Gun.obj.map(val, function(val, field){ // by default it maps over everything.
|
||||
var gun = this, ctx = {};
|
||||
opt = (Gun.obj.is(opt)? opt : (opt? {node: true} : {}));
|
||||
cb = cb || function(){};
|
||||
|
||||
gun._.status('node').event(function($){
|
||||
var node = gun.__.graph[$.soul];
|
||||
Gun.obj.map(node, function(val, field){
|
||||
if(Gun._.meta == field){ return }
|
||||
if(Gun.is.soul(val)){
|
||||
gun.get(val).val(function(val){ // should map have support for `.not`?
|
||||
@ -536,7 +538,6 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
var ahead = gun.chain(); return ahead;
|
||||
return gun;
|
||||
}
|
||||
Chain.not = function(cb){
|
||||
|
@ -1238,18 +1238,18 @@ describe('Gun', function(){
|
||||
});
|
||||
});
|
||||
});
|
||||
return;
|
||||
|
||||
it('map', function(done){
|
||||
var c = 0, map = gun.put({a: {here: 'you'}, b: {go: 'dear'}, c: {sir: '!'} });
|
||||
map.map(function(obj, soul){
|
||||
map.map(function(obj, field){
|
||||
c++;
|
||||
if(soul === 'a'){
|
||||
if(field === 'a'){
|
||||
expect(obj.here).to.be('you');
|
||||
}
|
||||
if(soul === 'b'){
|
||||
if(field === 'b'){
|
||||
expect(obj.go).to.be('dear');
|
||||
}
|
||||
if(soul === 'c'){
|
||||
if(field === 'c'){
|
||||
expect(obj.sir).to.be('!');
|
||||
}
|
||||
if(c === 3){
|
||||
|
Loading…
x
Reference in New Issue
Block a user