Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor, in preparation for changing to base events model
- Loading branch information
1 parent
cade4c7
commit 8e78c6f
Showing
7 changed files
with
188 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var map = require('iterate').map | ||
|
||
module.exports = | ||
function createID () { | ||
return map(3, function (i) { | ||
return Math.random().toString(16).substring(2).toUpperCase() | ||
}).join('') | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var Scuttlebutt = require('./index') | ||
var inherits = require('util').inherits | ||
var each = require('iterate').each | ||
|
||
module.exports = Model | ||
|
||
inherits(Model, Scuttlebutt) | ||
|
||
function Model (id) { | ||
if(!(this instanceof Model)) return new Model(id) | ||
Scuttlebutt.call(this, id) | ||
|
||
var store = this.store = {} | ||
|
||
this.on('data', function (update) { | ||
store[update[0]] = update | ||
}) | ||
} | ||
|
||
var m = Model.prototype | ||
|
||
m.set = function (k, v) { | ||
return this.localUpdate(k, v) | ||
} | ||
|
||
m.get = function (k) { | ||
if(this.store[k]) | ||
return this.store[k][1] | ||
} | ||
|
||
m.histroy = function (filter) { | ||
var self = this | ||
var h = [] | ||
each(this.store, function (e) { | ||
if(self.filter(e, filter)) | ||
h.push(e) | ||
}) | ||
return h | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var gossip = require('..') | ||
var gossip = require('../model') | ||
var assert = require('assert') | ||
|
||
var g1 = gossip() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var gossip = require('..') | ||
var gossip = require('../model') | ||
var assert = require('assert') | ||
|
||
var g1 = gossip() | ||
|
Don't have single letter variable names that are not function local.
var d = duplex()
is also bad but at least it's only 10 lines up.