0

How to make gun.not() to work with nested nodes?

Do we have any other technique to init a nested node?

The .not() method works if I deal with root level nodes. But in case of a nested node, I just get undefined when I want to get the node values.

var gun = new Gun();
var app = gun.get('app');
var demo = document.getElementById('demo');

deleteDino('dino/velociraptor');
initDino('dino/velociraptor');

app.get('dino/velociraptor').get('statistics').val(function(value) {
  console.log('value', value);
  demo.innerHTML = JSON.stringify(value);
});

function deleteDino (name) {
  app.get(name).put(null);
}

function initDino (name) {
  app.get(name).not(function () {
    app.get(name).put({
     statistics: {
       force: 5,
        speed: 17,
        intelligence: 23
      }
    });
  });
}
<script src="https://rawgit.com/amark/gun/master/gun.js"></script>
<script src="https://rawgit.com/amark/gun/master/lib/not.js"></script>
<p id="demo"></p>
srgbnd
  • 5,404
  • 9
  • 44
  • 80

1 Answers1

1

Works as expected.

putting 'null' into the dino name means it exists. Not tests for existance, not blankness.

J Decker
  • 537
  • 5
  • 9
  • My bad, a typo, I required not.js before gun.js, corrected. But it still doesn't work! – srgbnd Nov 02 '17 at 11:41
  • Then how to delete `dino/velociraptor` node completely to make `.not()` method work? – srgbnd Nov 02 '17 at 14:25
  • app.put(null) of course that will delete everything not just dino/velociraptor... maybe a variant of gun-unset could be made gun-delete that would take a node name and set the back reference to itself to null... *goes to work on that* – J Decker Nov 02 '17 at 20:40
  • really can't delete from known paths. The best I could do is find the parent, save all the existing members of that node, do a put(null) and then put all the members that did not match back. However, if this operation happened on one instance of gun, there is no delete of that field on remotes, and eventually what was on other systems would come back in. There would be no way to mark the data as actually deleted. Using set(), internal unique keys in the set are maintained, so it is possible to unset() a member and transmit that change. – J Decker Nov 02 '17 at 21:15