meteor-methods
v0.3.0
Published
ES6 import/export support for Meteor methods.
Downloads
28
Maintainers
Readme
meteor-methods
ES6 import/export support for Meteor methods.
Installation
meteor npm install --save meteor-methods
Example Usage
// customerMethods.js
import { Method } from 'meteor-methods';
import { Customers } from '/lib/collections';
export const addCustomer = new Method('Customers_addCustomer', function (personName) {
check(personName, String);
if (Customers.findOne({personName})) {
throw new Meteor.Error('Customer with that name already exists.');
}
return Customers.insert({personName, createdBy: this.userId});
});
// customersTemplate.js
import { testMethod } from './customerMethods.js';
/* ... */
function onAddCustomerClick(personName) {
addCustomer(personName, (err, res) => {
if (err) {
alert(`Error: ${ err.message }`);
}
alert(`Added customer with id: ${ res }`);
});
}