<commit_before># Publish Counts

A package to help you publish the count of a cursor, in real time.

## Installation

``` sh
$ meteor add tmeasday:publish-counts
```

## API

### Counts.publish [server]

`Counts.publish(subscription, counter-name, cursor, options)`

Simply call `Counts.publish` within a publication, passing in a name and a cursor:

#### Example 1
##### JavaScript
```js
Meteor.publish('posts', function() {
  Counts.publish(this, 'number-of-posts', Posts.find());
  return Posts.find();
});
```

##### Coffeescript
```coffeescript
Meteor.publish 'publication', ->
  Counts.publish this, 'name-of-counter', Posts.find()
  return undefined    # otherwise coffeescript returns a Counts.publish
                      # handle when Meteor expects a Mongo.Cursor object.
```

The `Counts.publish` function returns the observer handle that's used to maintain the counter. You can call its `stop` method in order to stop the observer from running.

Make sure you `.find()` separately for the counter and publish return, otherwise you'll get an empty document.

For more info regarding the `options` parameter, see [Options](#options).

### Counts.get [client]

`Counts.get(counter-name)`

Once you've subscribed to `'publication'` ([Ex 1](#example-1)), you can call `Counts.get('name-of-counter')` to get the value of the counter, reactively.<commit_msg>leave example consistent with coffeescript, improve warning<commit_after># Publish Counts

A package to help you publish the count of a cursor, in real time.

## Installation

``` sh
$ meteor add tmeasday:publish-counts
```

## API

### Counts.publish [server]

`Counts.publish(subscription, counter-name, cursor, options)`

Simply call `Counts.publish` within a publication, passing in a name and a cursor:

#### Example 1
##### JavaScript
```js
Meteor.publish('publication', function() {
  Counts.publish(this, 'name-of-counter', Posts.find());
  return Posts.find();
});
```

##### Coffeescript
```coffeescript
Meteor.publish 'publication', ->
  Counts.publish this, 'name-of-counter', Posts.find()
  return undefined    # otherwise coffeescript returns a Counts.publish
                      # handle when Meteor expects a Mongo.Cursor object.
```

The `Counts.publish` function returns the observer handle that's used to maintain the counter. You can call its `stop` method in order to stop the observer from running.

Warning: Make sure you call *collection*`.find()` separately for `Counts.publish` and the `Meteor.publish` return value, otherwise you'll get empty documents on the client.

For more info regarding the `options` parameter, see [Options](#options).

### Counts.get [client]

`Counts.get(counter-name)`

Once you've subscribed to `'publication'` ([Ex 1](#example-1)), you can call `Counts.get('name-of-counter')` to get the value of the counter, reactively.
{'fraction_non_alphanumeric': 0.12728551336146274, 'fraction_numerical': 0.002109704641350211, 'mean_word_length': 4.556640625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3239206', 'n_tokens_mistral': 863, 'n_tokens_neox': 806, 'n_words': 310}