Skip to content

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

Notifications You must be signed in to change notification settings

Didericis/callpromise-mixin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published