如何从集合中删除节点?

How to delete a node from set?

如何从集合中删除节点?

例如,我想从 dinos 集合中删除 velociraptor。但是当我 运行 脚本时,在 dinos.map().val(cb) 执行后我仍然看到 dinos 后面有两个节点。

const Gun = require('gun');    
const gun = new Gun({ peers: [ 'https://localhost:8888/gun' ] });

const app = gun.get('park');
const dinos = app.get('dinos');

const velociraptor = app.get('velociraptor').put({
  statistics: {
    force: 9,
    speed: 15
  }
});

const trex = app.get('trex').put({
  statistics: {
    force: 25,
    speed: 5
  }
});

dinos.set(velociraptor);
dinos.set(trex);

//velociraptor.put(null);
app.get('velociraptor').put(null);

dinos.map().val((v, k) => {
  console.log(k);
  console.log(v);
});

可以试试这个 npm 包,它提供了 'unset()' gun 的方法。

http://npmjs.com/package/gun-unset