git ssb

2+

Dominic / pull-stream



Commit bffa53fb184e86b8070bd6d059813eb100b8ebb4

refactor out tests to reuse

Dominic Tarr committed on 4/15/2013, 10:51:06 PM
Parent: e009a08c7f44e7c7f9c2890d8f00780b1819ebe2

Files changed

sinks.jschanged
throughs.jschanged
util.jsadded
sinks.jsView
@@ -1,4 +1,8 @@
1+var u = require('./util')
2+var prop = u.prop
3+var id = u.id
4+
15 var drain = exports.drain = function (read, op, done) {
26 ;(function next() {
37 var sync = true, returned = false, loop = true
48 do {
throughs.jsView
@@ -1,16 +1,9 @@
1-function prop (map) {
2- if('string' == typeof map) {
3- var key = map
4- return function (data) { return data[key] }
5- }
6- return map
7-}
1+var u = require('./util')
2+var prop = u.prop
3+var id = u.id
4+var tester = u.tester
85
9-function id (item) {
10- return item
11-}
12-
136 var map = exports.map =
147 function (read, map) {
158 map = prop(map) || id
169 return function (end, cb) {
@@ -35,12 +28,9 @@
3528
3629 var filter = exports.filter =
3730 function (read, test) {
3831 //regexp
39- if('object' === typeof test
40- && 'function' === typeof test.test)
41- test = test.test.bind(test)
42- test = prop(test) || id
32+ test = tester(test)
4333 return function next (end, cb) {
4434 read(end, function (end, data) {
4535 if(!end && !test(data))
4636 return next(end, cb)
@@ -75,8 +65,11 @@
7565 var n = test; test = function () {
7666 return n --
7767 }
7868 }
69+ // else
70+// test = tester(test)
71+
7972 return function (end, cb) {
8073 if(ended) return cb(ended)
8174 if(1 === more) end = true
8275 if(ended = end) return read(ended, cb)
util.jsView
@@ -1,0 +1,23 @@
1+exports.id =
2+function (item) {
3+ return item
4+}
5+
6+exports.prop =
7+function (map) {
8+ if('string' == typeof map) {
9+ var key = map
10+ return function (data) { return data[key] }
11+ }
12+ return map
13+}
14+
15+exports.tester = function (test) {
16+ if(!test) return exports.id
17+ if('object' === typeof test
18+ && 'function' === typeof test.test)
19+ return test.test.bind(test)
20+ return exports.prop(test) || exports.id
21+}
22+
23+

Built with git-ssb-web