Helper decorators for meteor
$ npm install meteor-decorators
import { MeteorClass, MeteorPublish, MeteorMethod } from 'meteor-decorators';
@MeteorClass
export class SomeClass {
/*
*
* 'dataList' will be published as 'data.list'
* e.g. 'dataListPublic' will be published as 'data.list.public'
* any arguments to Meteor.subscribe will be passed directly into this method
*/
@MeteorPublish()
public dataList(arg1: string, arg2: string): ObservableCursor<T> {
return Collection.find(
// do query
);
}
/*
*
* 'someMeteorMethod' can be called by Meteor.call with the same name
* any arguments to Meteor.call will be passed directly into this method
*/
@MeteorMethod()
public someMeteorMethod(arg1: string, arg2: string): void {
// do something
}
}
The class decorator will add Meteor publication & method scope properties to decorated class directly.
You can access those properties & method from this.scope
.
Currently there is no way to mutate class by decorators. In order to suppress type warnings, the following is one of possible workaround.
// when calling unblock of meteor method
// cast 'this' to any type
(this as any).scope.unblock();
Related issue: https://github.com/Microsoft/TypeScript/issues/4881