/callpromise-mixin

A mixin for the mdg:validated-method package that adds a callPromise method

Primary LanguageJavaScript

didericis:callpromise-mixin

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.

Install

$ meteor add didericis:callpromise-mixin

Usage

How to define

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
        }
    }
});

How to call

testMethod.callPromise({
    val: 'hi'
}).then(function(result){
    console.log('message', result.message);
    console.log('val', result.val);
}).catch(function(err){
    console.log(err);
});