Skip to content
Browse files

do not use method ~_~

  • Loading branch information...
1 parent cb9d2e2 commit 82767b13d985103bb49ce7610b1a8e232a6556d5 @Raynos committed Mar 5, 2013
Showing with 46 additions and 36 deletions.
  1. +32 −29 cursor.js
  2. +1 −0 examples/simple.js
  3. +6 −2 find.js
  4. +7 −5 package.json
View
61 cursor.js
@@ -1,36 +1,39 @@
-var reduce = require("reducible/reduce")
+var reducible = require("reducible/reducible")
var end = require("reducible/end")
var isReduced = require("reducible/is-reduced")
-var Cursor = require("mongodb").Cursor
-reduce.define(Cursor, function (cursor, next, initial) {
- var result = initial
+module.exports = CursorReduce
- recurse()
+function CursorReduce(cursor) {
+ return reducible(function (next, initial) {
+ var result = initial
- function recurse() {
- cursor.nextObject(function (error, value) {
- if (error) {
- if (typeof error === "string") {
- error = new Error(error)
+ recurse()
+
+ function recurse() {
+ cursor.nextObject(function (error, value) {
+ if (error) {
+ if (typeof error === "string") {
+ error = new Error(error)
+ }
+
+ return next(error, result)
+ }
+
+ if (value === null) {
+ return next(end, result)
}
- return next(error, result)
- }
-
- if (value === null) {
- return next(end, result)
- }
-
- result = next(value, result)
-
- if (isReduced(result)) {
- cursor.close(function () {
- next(end, result.value)
- })
- } else {
- recurse()
- }
- })
- }
-})
+ result = next(value, result)
+
+ if (isReduced(result)) {
+ cursor.close(function () {
+ next(end, result.value)
+ })
+ } else {
+ recurse()
+ }
+ })
+ }
+ })
+}
View
1 examples/simple.js
@@ -17,6 +17,7 @@ var insertResult = insert(collection, {
var findResult = expand(insertResult, function (item) {
assert.equal(item.hello, "world")
+ console.log("item", item)
return findOne(collection, {
_id: item._id
})
View
8 find.js
@@ -1,13 +1,17 @@
var expand = require("reducers/expand")
var callback = require("callback-reduce")
-var cursor = require("./cursor")
+var CursorReduce = require("./cursor")
+
+// var cursor = require("./cursor")
module.exports = find
function find(collection, selector, options) {
return expand(collection, function (collection) {
- return callback.call(collection, collection.find
+ var cursor = callback.call(collection, collection.find
, selector || {}, options || {})
+
+ return expand(cursor, CursorReduce)
})
}
View
12 package.json
@@ -21,17 +21,19 @@
"reducers": "Raynos/reducers",
"mongodb": "~1.2.7",
"callback-reduce": "Raynos/callback-reduce",
- "cache-reduce": "Raynos/cache-reduce"
+ "cache-reduce": "Raynos/cache-reduce",
+ "introspect": "0.0.2"
},
"peerDependencies": {
- "reducible": "~1.0.5"
+ "reducible": "Raynos/reducible#1.x"
},
"devDependencies": {
- "tape": "0.1.5",
- "reducible": "~1.0.5",
+ "tape": "git://github.com/Raynos/tape",
+ "reducible": "Raynos/reducible#1.x",
"browserify": "https://github.com/raynos/node-browserify/tarball/master",
"testem": "0.2.52",
- "node-uuid": "~1.4.0"
+ "node-uuid": "~1.4.0",
+ "introspect": "0.0.2"
},
"licenses": [
{

0 comments on commit 82767b1

Please sign in to comment.
Something went wrong with that request. Please try again.