Skip to content
Mark Nadal edited this page Jun 18, 2018 · 1 revision

Implementing other CRDTs on top of GUN's CRDT can be done in just 12 lines of code, and automatically synchronizes in realtime across a P2P mesh network:

Gun.chain.count = function (num) {
  if (typeof num === 'number') {
    this.set(num);
  }
  if (typeof num === 'function') {
    var sum = 0;
    this.map().once(function (val) {
      num(sum += val);
    });
  }
  return this;
};

Example usage:

var db = gun.get('count')
db.count(+5)
db.count(-8)
db.count(function (value) {
  console.log(value) // 5, -3
})
// prints: 5
// prints: -3
db.count(+10)
// prints: 7

This wiki is where all the GUN website documentation comes from.

You can read it here or on the website, but the website has some special features like rendering some markdown extensions to create interactive coding tutorials.

Please feel free to improve the docs itself, we need contributions!

Clone this wiki locally