Reputation: 5634
gun 0.8.7, Node.js-to-Node.js, no browser.
Nodes are successfully created and added to the tasks
set
const Gun = require('gun');
const _ = require('lodash');
require( "gun/lib/path" );
const gun = new Gun({peers:['http://localhost:8080/gun', 'http://localhost:8081/gun']});
const watchers = [
{
id: '123',
type: 'skeleton',
stat: {
num: 0
}
},
{
id: '456',
type: 'snowmann',
stat: {
num: 0
}
},
{
id: '789',
type: 'moose',
stat: {
num: 0
},
}
];
const tasks = gun.get('tasks');
_.forEach(watchers, function (watcher) {
let task = gun.get(`watcher/${watcher.id}`).put(watcher);
tasks.set(task);
});
There are results of the .map
evaluation
a2task { _:
{ '#': 'watcher/123',
'>': { id: 1506959623558, type: 1506959623558, stat: 1506959623558 } },
id: '123',
type: 'skeleton',
stat: { '#': 'j8acunbf70NblJptwXWa' } }
task { _:
{ '#': 'watcher/456',
'>':
{ id: 1506959623579.002,
type: 1506959623579.002,
stat: 1506959623579.002 } },
id: '456',
type: 'snowmann',
stat: { '#': 'j8acunbv03sor9v0NeHs7cITj' } }
task { _:
{ '#': 'watcher/789',
'>':
{ id: 1506959623581.002,
type: 1506959623581.002,
stat: 1506959623581.002 } },
id: '789',
type: 'moose',
stat: { '#': 'j8acunbx03sorM0hWZdQz0IyL' } }
on a listener side
const Gun = require('gun');
const gun = new Gun({peers:['http://localhost:8080/gun']});
const tasks = gun.get('tasks');
tasks.map().val(function (task) {
console.log('task', task);
});
But there are no results if one of the properties updated:
_.forEach(watchers, function (watcher) {
gun.get(`watcher/${watcher.id}`).put({
stat: {
num: 1
}
});
Why?
Here is the code to play with https://github.com/sergibondarenko/shared-schedule
Upvotes: 1
Views: 101
Reputation: 586
It gets no update because you're not mapping that level. 'stat' is already a property that is an object so you get no change.
tasks.map().map().val(function (task_stat) {
console.log('task stat', task_stat);
});
Upvotes: 1