Skip to content

Commit bcc5f1f

Browse files
committed
update so that you can pass your own state object
1 parent 959e526 commit bcc5f1f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ with some sample defaults.
6363
### `require('simple-scuttle').Gossip` ###
6464

6565
```js
66-
Gossip(String id, Object config) -> gossip
66+
Gossip(String id, Object config, Object state) -> gossip
6767
```
6868

6969
- `id`: The unique identifier for each `Gossip` instance.
@@ -82,6 +82,7 @@ Gossip(String id, Object config) -> gossip
8282
and will be called by Array.sort under the hood. This function is used to
8383
order updates when another Gossip instance requests updates more recent
8484
than a given version number.
85+
- `state`: if you would like to pass a specific object to the Gossip to use as its key value store, perhaps a [proxy object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Meta_programming) which you have overrided to be backed by a database.
8586

8687
# Admonition #
8788

lib/gossip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ util.inherits(Gossip, Stream.Transform)
88

99
module.exports = Gossip
1010

11-
function Gossip(id, config) {
11+
function Gossip(id, config, state) {
1212
if(!(this instanceof Gossip)) {
1313
return Gossip.apply(Object.create(proto), arguments)
1414
}
@@ -36,7 +36,7 @@ function Gossip(id, config) {
3636
, config.sort
3737
)
3838

39-
this.state = {}
39+
this.state = state || {}
4040
this.id = id
4141
this.backlog = []
4242

0 commit comments

Comments
 (0)