role.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ;(function(){
  2. function resolve(chain){
  3. /*
  4. If we say "Spray paint all of Bob's friends' cat blue",
  5. the embedded question we might need to ask is:
  6. If one of Bob's friends winds up unfriending him,
  7. AND has their cat die that they get a new cat,
  8. do we want THAT cat painted blue?
  9. I believe the answer is NO.
  10. */
  11. // soul.key=value
  12. // soul ???
  13. // stream -> soul.key ...
  14. // stream -> soul.key
  15. // if you have a dynamic map, and you want to "process it", you wind up waiting until at least 1 item exists, calling off, then calling each.
  16. // in this sense, resolve can only know it has processed each item once, but not whether it itself is done. and that is fair.
  17. // what about ops that read before writing like timegraph?
  18. //console.debug.i=1;console.log("----------------");
  19. /*
  20. gun.get('a').get('b').put({
  21. x: {
  22. x1: {c: {d: {'yay':1}}},
  23. x2: {c: {d: {'cake':1}}}
  24. },
  25. y: {
  26. y1: {c: {d: {'foo':1}}},
  27. y2: {c: {d: {'bar':1}}}
  28. }
  29. });
  30. /*
  31. map {10:{}, 5:{}} -> get link to load
  32. */
  33. // FOR THIS CHAIN: Each item gets called 3 times.
  34. Gun.debug=1;
  35. //return;
  36. chain = chain || gun.get('a').get('b').map().map().get('c').get('d').get(function(a,b,c,tmp){
  37. // a.gun._.soul || a.gun._.link;
  38. a.ID = a.ID || Gun.text.random(2);
  39. console.log('********', a.put || a);//, Gun.node.soul(a.put), a.gun._);//, a.gun.back(function back(_){_.get && (tmp || (tmp = [])).push(_.get);return _.back? undefined : tmp;}));
  40. //b.rid(a);
  41. });
  42. console.log("~~~~~~~~~~~~~~");
  43. window.chain = chain;
  44. }
  45. /*
  46. sync put: 5 node - 1 stop
  47. sync reload: 1 link 2 node - X stop
  48. sync resolve: 6 node - 0 stop : 3 node - 0 stop
  49. async put: 5 node + 3 node - 1 stop
  50. async reload: 2 link 1 node - X stop (2 links per each stop)
  51. async resolve: 6 node - 0 stop : 3 node - 0 stop
  52. sync put: 1 mum
  53. sync reload: 1 mum
  54. sync resolve: 1 mum
  55. async put: 1 mum
  56. async reload: 0 mum: 2 link 1 node
  57. async resolve: 1 mum
  58. */
  59. function off(chain){
  60. //Gun.debug = 1;
  61. chain = chain || gun.get('users').map().get(function(a,b,c,tmp){
  62. console.log("***", a.put);
  63. b.rid(a);
  64. });
  65. gun.get('users').get('alice').get(function(a,b){
  66. console.log(">>>", a.put);
  67. });
  68. console.log("vvvvvvvvvvvvv");
  69. window.chain = chain;
  70. }
  71. /*
  72. gun.get('users').put({
  73. alice: {age: 29},
  74. bob: {age: 32}
  75. });
  76. */
  77. function soul(chain){
  78. Gun.debug = 1;
  79. gun.get('x').get('y').get('z').get('q').get(function(a,b,c){
  80. console.log("***", a.put || a);//,b,c);
  81. });
  82. setTimeout(function(){
  83. console.debug.j=1;
  84. console.debug.i=1;console.log("------------");
  85. gun.get('x').get('y').put({
  86. z: {
  87. q: {r: {hello: 'world'}}
  88. }
  89. });
  90. },20);
  91. console.log("..............");
  92. window.chain = chain;
  93. }
  94. /*
  95. gun.get('x').get('y').get('z').put({xyz: 'zyx'});
  96. */
  97. window.resolve = resolve;
  98. window.off = off;
  99. window.soul = soul;
  100. //localStorage.clear();sessionStorage.clear();
  101. setTimeout(function(){ resolve() },1);
  102. /*
  103. At the end of the day, you trust an entity, not data.
  104. That entity might be a person, or a group of people,
  105. it doesn't really matter - you do not trust a machine.
  106. Trust gives write access (public).
  107. Grant gives read access (private).
  108. */
  109. function Role(){}
  110. if(typeof window !== "undefined"){ Role.window = window }
  111. var Gun = (Role.window||{}).Gun || require('../gun');
  112. Gun.SEA || require('../sea');
  113. if(!Gun.User){ throw "No User System!" }
  114. var User = Gun.User;
  115. User.prototype.trust = function(user){
  116. }
  117. }());