Skip to content

Commit

Permalink
feat(jsdoc): Updated docs generation scripts and updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Oct 31, 2016
1 parent 50deb25 commit ded2eff
Show file tree
Hide file tree
Showing 4 changed files with 476 additions and 265 deletions.
174 changes: 92 additions & 82 deletions docs/MeteorObservable.md
Original file line number Diff line number Diff line change
@@ -1,122 +1,132 @@
<a name="MeteorComponent"></a>
<a name="MeteorObservable"></a>

## MeteorComponent
A class to extend in Angular 2 components.
Contains wrappers over main Meteor methods,
that does some maintenance work behind the scene.
For example, it destroys subscription handles
when the component is being destroyed itself.
## MeteorObservable
A class with static methods, which wraps Meteor's API and returns
RxJS Observable as return value for all Meteor's API.
The method's signature is the same as Metoer's, except you don't
need to provide callbacks, and you need to "subscribe" instead.
The functionality that wrapped in this implementation is Meteor.call,
Meteor.autorun and Meteor.subscribe.

**Kind**: global class

* [MeteorComponent](#MeteorComponent)
* _instance_
* [.autorun(func, autoBind)](#MeteorComponent+autorun) ⇒ <code>Tracker.Computation</code>
* [.subscribe(name, ...args, autoBind)](#MeteorComponent+subscribe) ⇒ <code>Meteor.SubscriptionHandle</code>
* [.call(name, ...args, autoBind)](#MeteorComponent+call) ⇒ <code>void</code>
* _inner_
* [~autorunCallback](#MeteorComponent..autorunCallback) : <code>function</code>
* [MeteorObservable](#MeteorObservable)
* [.call(name, ...args)](#MeteorObservable.call) ⇒ <code>Observable.&lt;T&gt;</code>
* [.subscribe(name, ...args)](#MeteorObservable.subscribe) ⇒ <code>Observable</code>
* [.autorun()](#MeteorObservable.autorun) ⇒ <code>Observable.&lt;T&gt;</code>

<a name="MeteorComponent+autorun"></a>
<a name="MeteorObservable.call"></a>

### meteorComponent.autorun(func, autoBind) ⇒ <code>Tracker.Computation</code>
Method has the same notation as Meteor.autorun
except the last parameter.
### MeteorObservable.call(name, ...args) ⇒ <code>Observable.&lt;T&gt;</code>
Method has the same notation as Meteor.call, only without the callbacks:
MeteorObservable.call(name, [...args])

**Kind**: instance method of <code>[MeteorComponent](#MeteorComponent)</code>
**Returns**: <code>Tracker.Computation</code> - - Object representing the Meteor computation
**See**
**Kind**: static method of <code>[MeteorObservable](#MeteorObservable)</code>
**Returns**: <code>Observable.&lt;T&gt;</code> - - RxJS Observable, which completes when the server return a response.

- [Tracker.Computation in Meteor documentation](https://docs.meteor.com/api/tracker.html#tracker_computation)
- [autorun in Meteor documentation](https://docs.meteor.com/api/tracker.html#Tracker-autorun)
| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | Name of the method in the Meteor server |
| ...args | <code>any</code> | Parameters that will be forwarded to the method. after the func call to initiate change detection. |

**Example** *(Example using Angular2 Component)*
```js
class MyComponent {
constructor() {

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| func | <code>[autorunCallback](#MeteorComponent..autorunCallback)</code> | | Callback to be executed when current computation is invalidated. The Tracker.Computation object will be passed as argument to this callback. |
| autoBind | <code>Boolean</code> | <code>true</code> | Determine whether Angular2 Zone will run after the func call to initiate change detection. |
}

**Example**
```js
class MyComponent extends MeteorComponent {
private myData: Mongo.Cursor;
private dataId: any;

constructor() {
super();

this.autorun(() => {
this.myData = MyCollection.find({ _id: dataId});
}, true);
}
}
doAction(payload) {
MeteorObservable.call("myData", payload).subscribe((response) => {
// Handle success and response from server!
}, (err) => {
// Handle error
});
}
}
```
<a name="MeteorComponent+subscribe"></a>
<a name="MeteorObservable.subscribe"></a>

### meteorComponent.subscribe(name, ...args, autoBind) ⇒ <code>Meteor.SubscriptionHandle</code>
Method has the same notation as Meteor.subscribe:
subscribe(name, [args1, args2], [callbacks], [autoBind])
except the last autoBind param (see autorun above).
### MeteorObservable.subscribe(name, ...args) ⇒ <code>Observable</code>
Method has the same notation as Meteor.subscribe, only without the callbacks:
subscribe(name, [...args])

**Kind**: instance method of <code>[MeteorComponent](#MeteorComponent)</code>
**Returns**: <code>Meteor.SubscriptionHandle</code> - - The handle of the subscription created by Meteor.
**See**: [Publication/Subscription in Meteor documentation](http://docs.meteor.com/api/pubsub.html)
You can use this method from any Angular2 element - such as Component, Pipe or
Service.

**Kind**: static method of <code>[MeteorObservable](#MeteorObservable)</code>
**Returns**: <code>Observable</code> - - RxJS Observable, which completes when the subscription is ready.
**See**: [Publications in Meteor documentation](http://docs.meteor.com/api/pubsub.html)

| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | Name of the publication in the Meteor server |
| ...args | <code>any</code> | Parameters that will be forwarded to the publication. |
| autoBind | <code>Boolean</code> | Determine whether Angular 2 zone will run after the func call to initiate change detection. |
| ...args | <code>any</code> | Parameters that will be forwarded to the publication. after the func call to initiate change detection. |

**Example**
**Example** *(Example using Angular2 Service)*
```js
class MyComponent extends MeteorComponent {
class MyService {
private meteorSubscription: Observable<any>;

constructor() {
super();

this.subscribe("myData", 10);
}

subscribeToData() {
this.meteorSubscription = MeteorObservable.subscribe<any>("myData").subscribe(() => {
// Subscription is ready!
});
}

unsubscribeToData() {
this.meteorSubscription.unsubscribe();
}
}


```
<a name="MeteorComponent+call"></a>

### meteorComponent.call(name, ...args, autoBind) ⇒ <code>void</code>
Method has the same notation as Meteor.call:
call(name, [args1, args2], [callbacks], [autoBind])
except the last autoBind param (see autorun above).
**Example** *(Example using Angular2 Component)*
```js
class MyComponent implements OnInit, OnDestroy {
private meteorSubscription: Observable<any>;

**Kind**: instance method of <code>[MeteorComponent](#MeteorComponent)</code>
constructor() {

| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | Name of the publication in the Meteor server |
| ...args | <code>any</code> | Parameters that will be forwarded to the method. |
| autoBind | <code>Boolean</code> | autoBind Determine whether Angular 2 zone will run after the func call to initiate change detection. |
}

**Example**
```js
class MyComponent extends MeteorComponent {
constructor() {
super();
ngOnInit() {
this.meteorSubscription = MeteorObservable.subscribe("myData").subscribe(() => {
// Subscription is ready!
});
}

this.call("serverMethod", (err, result) => {
// Handle response...
});
ngOnDestroy() {
this.meteorSubscription.unsubscribe();
}
}


```
<a name="MeteorComponent..autorunCallback"></a>
<a name="MeteorObservable.autorun"></a>

### MeteorComponent~autorunCallback : <code>function</code>
This callback called when autorun triggered by Meteor.
### MeteorObservable.autorun() ⇒ <code>Observable.&lt;T&gt;</code>
Method has the same notation as Meteor.autorun, only without the callback:
MeteorObservable.autorun()

**Kind**: inner typedef of <code>[MeteorComponent](#MeteorComponent)</code>
**Kind**: static method of <code>[MeteorObservable](#MeteorObservable)</code>
**Returns**: <code>Observable.&lt;T&gt;</code> - - RxJS Observable, which trigger the subscription callback
each time that Meteor Tracker detects a change.
**Example** *(Example using Angular2 Component)*
```js
class MyComponent {
constructor() {

| Param | Type |
| --- | --- |
| computation | <code>Tracker.Computation</code> |
}

doAction(payload) {
MeteorObservable.autorun().subscribe(() => {
// Handle Tracker autorun change
});
}
}
```
Loading

0 comments on commit ded2eff

Please sign in to comment.