0.0.3 • Published 5 years ago

meteor-publication v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Installation

`meteor npm i --save meteor-publication'

Usage

Create a publication:

import Publication from 'meteor-publication';

export default new Publication('foo', function(now) {
  return Collection.stuff.find({someField: now.getDate()});
});

Use the publication you created:

import fooPublication from './foo';

fooPublication.subscribe(new Date());

This replaces the traditional way of creating and calling Meteor publications:

import { Meteor } from 'meteor/meteor';

// Create a publication
Meteor.publish('foo', function(now) {
  return Collection.stuff.find({someField: now.getDate()});
});

// Subscribe to the publication
Meteor.subscribe('foo', new Date());

This removes reliance on magic strings and enables type checking if you use TypeScript (see below).

API

Publication#subscribe: returns a standard Meteor subscription object with stop(), and ready() methods, and the subscriptionId property.

Publication#withData: returns an object with a subscribe method that, when called, will subscribe with the data you supplied in this call.

Notes for TypeScript:

This module comes with typings. Visual Studio Code supports full type inference:

import Publication from 'meteor-publication';

const fooPublication = new Publication('foo', function(now: Date) {
  return now.getDate();
});
fooPublication.call(1); // Error since you are passing a number instead of a date

TypeScript currently doesn't support inference if you have 0 arguments, so this will give you an error:

import Publication from 'meteor-publication';

const fooPublication = new Publication('foo', function() {
  return 1;
});
fooPublication.call(); // Error because TypeScript still thinks you should pass an argument.

Instead, use the PublicationWithoutArgs class:

import {PublicationWithoutArgs} from 'meteor-publication';

const fooPublication = new PublicationWithoutArgs('foo', function() {
  return 1;
});
fooPublication.call(); // All good
0.0.3

5 years ago

0.0.2-beta.4

5 years ago

0.0.2-beta.3

5 years ago

0.0.2-beta.2

7 years ago

0.0.2-beta.1

7 years ago

0.0.1

7 years ago