Skip to content

Commit

Permalink
Merge branch 'brookback-feature/add-promises'
Browse files Browse the repository at this point in the history
  • Loading branch information
johanbrook committed Feb 3, 2018
2 parents 78eeddf + aff5727 commit b9bea3d
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 2,267 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": "lookback/meteor",

"globals": {
"PublicationCollector": true
"PublicationCollector": true,
"Documents": true,
"Books": true
}
}
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,42 @@ const collector = new PublicationCollector(opts);

An instance of `PublicationCollector` also is an `EventEmitter`, and emits a `ready` event when the publication is marked as ready.

### PublicationCollector.collect
### PublicationCollector.collect -> Promise

```js
collector.collect(publicationName, publicationArgs..., callback);
collector.collect(publicationName, [publicationArgs..., callback]);
```

- `publicationName (String)`: the name of the publication (String)
- `publicationArgs`: zero or more arguments to the publication
- `callback (Function)`: The function to be called when the publication is ready. The function will be provided with a `collections` object containing key:value pairs where the key is the name of a collection that the publication published and the value is an array of the documents that were published in that collection.
- `callback (Function)`: Optional. The function to be called when the publication is ready. Will be called with a `collections` object.

Returns a Promise which resolves to a `collections` object.

The `collections` value is an object containing key:value pairs where the key is the name of a collection that the publication published and the value is an array of the documents that were published in that collection.

```js
collector.collect('myPublication', firstPublicationArg, secondPublicationArg, (collections) => {
assert.equal(collections.myCollection.length, 10);
});
```

or use Promises:

```js
const collector = new PublicationCollector();

collector.collect('myPublication')
.then(collections => {
// assertions..
})
.catch(ex => /* error handling */);

// Or async/await style
const collections = await collector.collect('myPublication');
// assertions..
```

## Development

```
Expand Down Expand Up @@ -107,10 +127,11 @@ Based on https://github.com/stubailo/meteor-rest/blob/devel/packages/rest/http-s

## Releases

- `1.2.0`
- `1.1.0`
- Pin versions to Meteor@>=1.3.
- Throw error when there's no publication for the provided name.
- Upgrade dependencies.
- Add support for Promises in the `.collect()` method.
- `1.0.10` - Always stop the publication when an error is thrown in the PublicationCollector callback. Thanks @SimonSimCity !
- `1.0.9` - Fix bug in 1.0.8 regarding empty array return. Thanks @nkahnfr !
- `1.0.8` - Fix support for publications returning nothing (an empty array). Thanks @ziedmahdi !
Expand Down
Loading

0 comments on commit b9bea3d

Please sign in to comment.