在 someModel
里面:
exports.findAll = thunkify(function findAllT(cb) {
sysUserModel.find({}, function(err, objs) {
cb(err, objs);
})
});
exports.findOne = thunkify(function findOneT(_conditions, cb) {
sysUserModel.findOne(_conditions, function(err, o) {
cb(err, o);
})
});
exports.findById = thunkify(function findByIdT(_id, cb) {
sysUserModel.findById(_id, function(err, o) {
cb(err, o);
})
});
在要用的地方 var model = require('someModel');
有没有可以统一 thunkify someModel exports
下面的所有方法的方式?
4 回复
https://github.com/node-modules/node-thunkify-wrap
var thunkify = require('thunkify-wrap');
exports.findOne = function (args, callback) {
// ...
};
exports.findById = function (args, callback) {
// ...
}
thunkify(exports);
see https://github.com/cnpm/cnpmjs.org/blob/master/proxy/module_log.js