A mixin for the mdg:validated-method package that adds callPromise
.
It is the equivalent of using the mdg:validated-method call
, but instead of accepting a callback, it returns a promise.
$ meteor add didericis:callpromise-mixin
import { CallPromiseMixin } from 'meteor/didericis:callpromise-mixin';
testMethod = new ValidatedMethod({
name: 'testMethod',
mixins: [CallPromiseMixin],
validate: function(input) {
if (!input || !input.val) {
throw new Meteor.Error('Need input.val');
}
},
run(input) {
return {
message: 'Success!',
val: input.val
}
}
});
testMethod.callPromise({
val: 'hi'
}).then(function(result){
console.log('message', result.message);
console.log('val', result.val);
}).catch(function(err){
console.log(err);
});