如果更新项目,则不会触发集合上的地图

Map on a set is not triggered if an item is updated

gun 0.8.7,Node.js-to-Node.js,没有浏览器。

节点已成功创建并添加到 tasks

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);
});

.map评价的结果

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' } }

在听众方面

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);
});

但是如果更新了其中一个属性,则没有结果:

_.forEach(watchers, function (watcher) {
  gun.get(`watcher/${watcher.id}`).put({
    stat: {
      num: 1
    }
  });

为什么?

下面是代码 https://github.com/sergibondarenko/shared-schedule

它没有更新,因为你没有映射那个级别。 'stat' 已经是一个 属性,它是一个对象,所以你不会得到任何改变。

tasks.map().map().val(function (task_stat) {
  console.log('task stat', task_stat);
});