Created
November 30, 2015 10:02
-
-
Save 1yx/60463ac7ea4bdafe909b to your computer and use it in GitHub Desktop.
扩展leancloud js sdk 中的一些方法
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
var AV = require('avoscloud-sdk').AV; | |
AV.Query.prototype.findAll = function () { | |
var self = this, | |
data = []; | |
self._limit = 1000; | |
self._order = 'createdAt'; | |
return loop(avpromise(0), function (skip) { | |
self._skip = skip; | |
return self.find(); | |
}); | |
function avpromise(resolved) { | |
return new AV.Promise(function (resolve) { | |
resolve(resolved); | |
}); | |
} | |
function loop(promise, fn) { | |
return promise.then(fn).then(function (rows) { | |
data = data.concat(rows); | |
return rows.length === self._limit ? loop(avpromise(self._skip + self._limit), fn) : avpromise(data); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment