Browse Source

add save fn

Kieran Gibb 2 years ago
parent
commit
9e26ace9fd
No known key found for this signature in database
2 changed files with 30 additions and 0 deletions
  1. 8
    0
      index.js
  2. 22
    0
      test/mock.js

+ 8
- 0
index.js View File

@@ -10,5 +10,13 @@ class BlindReplicator extends Base {
10 10
     this._initFeeds(opts)
11 11
     this._readyCallback = this.multifeed.ready.bind(this.multifeed)
12 12
   }
13
+
14
+  save () {
15
+    this.config.replicators.set(this.address, {
16
+      address: this.address,
17
+      name: this.name
18
+    })
19
+    return this.config.save()
20
+  }
13 21
 }
14 22
 

+ 22
- 0
test/mock.js View File

@@ -0,0 +1,22 @@
1
+const maybe = require('call-me-maybe')
2
+const crypto = require('cobox-crypto')
3
+
4
+module.exports = (storage, address, opts) => new BlindReplicator(storage, address, opts)
5
+
6
+class BlindReplicator {
7
+  constructor (storage, address, opts = {}) {
8
+    this.address = address
9
+    this.discoveryKey = crypto.randomBytes(32)
10
+    this.name = opts.name
11
+  }
12
+
13
+  ready (callback) {
14
+    return maybe(callback, new Promise((resolve, reject) => {
15
+      resolve(true)
16
+    }))
17
+  }
18
+
19
+  save () {
20
+    return true
21
+  }
22
+}