erase.js 667 B

1234567891011121314151617181920212223242526272829
  1. var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
  2. Gun.on('opt', function(root){
  3. this.to.next(root);
  4. if(root.once){ return }
  5. root.on('put', function(msg){
  6. Gun.graph.is(msg.put, null, function(val, key, node, soul){
  7. if(null !== val){ return }
  8. // TODO: Refactor this to use `.off()`?
  9. var tmp = root.graph[soul];
  10. if(tmp){
  11. delete tmp[key];
  12. }
  13. tmp = tmp && tmp._ && tmp._['>'];
  14. if(tmp){
  15. delete tmp[key];
  16. }
  17. tmp = root.next;
  18. if(tmp && (tmp = tmp[soul]) && (tmp = tmp.put)){
  19. delete tmp[key];
  20. tmp = tmp._ && tmp._['>'];
  21. if(tmp){
  22. delete tmp[key];
  23. }
  24. }
  25. });
  26. this.to.next(msg);
  27. });
  28. });