meteor-methods

0.3.0 • Public • Published

meteor-methods

ES6 import/export support for Meteor methods.

npm version

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

Package Sidebar

Install

npm i meteor-methods

Weekly Downloads

9

Version

0.3.0

License

MIT

Unpacked Size

4.51 kB

Total Files

4

Last publish

Collaborators

  • huttonr