|
8 | 8 | <do-nothing>
|
9 | 9 | {{#markdown}}
|
10 | 10 |
|
11 |
| -MeteorComponent |
| 11 | +# MeteorComponent |
| 12 | + |
| 13 | +MeteorComponent is a class to extend, you should extend this class by your implemented `@Component`s. |
| 14 | + |
| 15 | +This class provides the ability to use Meteor along with Angular 2.0 - you can use Meteor abilities with the required environment configuration for Angular 2.0. |
| 16 | + |
| 17 | +This basic component also handles the cleanup and destroy process that Angular 2.0 provides. |
| 18 | + |
| 19 | +When using TypeScript, import this component as `MeteorComponent`, from `angular2-meteor` module: |
| 20 | + |
| 21 | + import {MeteorComponent} from 'angular2-meteor'; |
| 22 | + |
| 23 | +#### Usage example |
| 24 | + |
| 25 | + @Component({ |
| 26 | + selector: 'my-component' |
| 27 | + }) |
| 28 | + @View({ |
| 29 | + template: 'Hello World!' |
| 30 | + }) |
| 31 | + class MyComponent extends MeteorComponent { |
| 32 | + constructor() { |
| 33 | + super(); |
| 34 | + |
| 35 | + // Wrapper for Meteor.autorun |
| 36 | + this.autorun(() => { |
| 37 | + // Meteor dependant code |
| 38 | + }); |
| 39 | + |
| 40 | + // Wrapper for Meteor.call |
| 41 | + this.call('myServerMethod'); |
| 42 | + |
| 43 | + // Wrapper for Meteor.subscribe |
| 44 | + this.subscribe('mySubscription'); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | +## API Reference |
| 49 | + |
| 50 | +### autorun |
| 51 | + |
| 52 | +This method is a wrapper of [Tracker.autorun](http://docs.meteor.com/#/full/tracker_autorun). |
| 53 | + |
| 54 | +The first argument of this method is a callback, which will be called each time Autorun will be triggered. |
| 55 | + |
| 56 | +The Autorun will stop automatically when when it's component is destroyed. |
| 57 | + |
| 58 | +<table class="variables-matrix input-arguments"> |
| 59 | + <thead> |
| 60 | + <tr> |
| 61 | + <th>Argument Name</th> |
| 62 | + <th>Type</th> |
| 63 | + <th>Description</th> |
| 64 | + <th>Default Value</th> |
| 65 | + <th>Required</th> |
| 66 | + </tr> |
| 67 | + </thead> |
| 68 | + <tbody> |
| 69 | + <tr> |
| 70 | + <td><strong>runFunc</strong></td> |
| 71 | + <td> |
| 72 | + <a href="" class="label type-hint type-hint-function">function</a> |
| 73 | + </td> |
| 74 | + <td><p> The function to run. It receives one argument: the Computation object that will be returned. </p> |
| 75 | + </td> |
| 76 | + <td></td> |
| 77 | + <td><a href="" class="label type-hint type-hint-object">Yes</a></td> |
| 78 | + </tr> |
| 79 | + <tr> |
| 80 | + <td>autoBind</td> |
| 81 | + <td> |
| 82 | + <a href="" class="label type-hint type-hint-boolean">boolean</a> |
| 83 | + </td> |
| 84 | + <td><p> Boolean that specify if to bind the callback to the NgZone of the component. </p> |
| 85 | + </td> |
| 86 | + <td>false</td> |
| 87 | + <td><a href="" class="label type-hint type-hint-object">No</a></td> |
| 88 | + </tr> |
| 89 | + </tbody> |
| 90 | +</table> |
| 91 | + |
| 92 | +### subscribe |
| 93 | + |
| 94 | +This method is a wrapper of [Tracker.subscribe](http://docs.meteor.com/#/full/meteor_subscribe). |
| 95 | + |
| 96 | +The method expect the publication name (as defined in the server), subscription arguments, result callback and boolean that indicates that auto-bind feature. |
| 97 | + |
| 98 | +The subscription will stop automatically when when it's component is destroyed. |
| 99 | + |
| 100 | +<table class="variables-matrix input-arguments"> |
| 101 | + <thead> |
| 102 | + <tr> |
| 103 | + <th>Argument Name</th> |
| 104 | + <th>Type</th> |
| 105 | + <th>Description</th> |
| 106 | + <th>Default Value</th> |
| 107 | + <th>Required</th> |
| 108 | + </tr> |
| 109 | + </thead> |
| 110 | + <tbody> |
| 111 | + <tr> |
| 112 | + <td><strong>publication</strong></td> |
| 113 | + <td> |
| 114 | + <a href="" class="label type-hint type-hint-string">string</a> |
| 115 | + </td> |
| 116 | + <td><p> The name of the publication, as defined in the server side using `Meteor.publish`. </p> |
| 117 | + </td> |
| 118 | + <td></td> |
| 119 | + <td><a href="" class="label type-hint type-hint-object">Yes</a></td> |
| 120 | + </tr> |
| 121 | + <tr> |
| 122 | + <td>arguments...</td> |
| 123 | + <td> |
| 124 | + <a href="" class="label type-hint">Any</a> |
| 125 | + </td> |
| 126 | + <td><p> Argument that will be passed to the publication method. </p> |
| 127 | + </td> |
| 128 | + <td></td> |
| 129 | + <td><a href="" class="label type-hint type-hint-object">No</a></td> |
| 130 | + </tr> |
| 131 | + <tr> |
| 132 | + <td>resultCallback</td> |
| 133 | + <td> |
| 134 | + <a href="" class="label type-hint type-hint-object">object</a> / |
| 135 | + <a href="" class="label type-hint type-hint-function">function</a> |
| 136 | + </td> |
| 137 | + <td><p> May include `onStop` and `onReady` callbacks. If there is an error, it is passed as an argument to `onStop`. If a function is passed instead of an object, it is interpreted as an `onReady` callback. </p> |
| 138 | + </td> |
| 139 | + <td></td> |
| 140 | + <td><a href="" class="label type-hint type-hint-object">No</a></td> |
| 141 | + </tr> |
| 142 | + <tr> |
| 143 | + <td>autoBind</td> |
| 144 | + <td> |
| 145 | + <a href="" class="label type-hint type-hint-boolean">boolean</a> |
| 146 | + </td> |
| 147 | + <td><p> Boolean that specify if to bind the callback to the NgZone of the component. </p> |
| 148 | + </td> |
| 149 | + <td>false</td> |
| 150 | + <td><a href="" class="label type-hint type-hint-object">No</a></td> |
| 151 | + </tr> |
| 152 | + </tbody> |
| 153 | +</table> |
| 154 | + |
| 155 | +### call |
| 156 | + |
| 157 | +This method is a wrapper of [Meteor.call](http://docs.meteor.com/#/full/meteor_call). |
| 158 | + |
| 159 | +This method invokes a method passing any number of arguments. |
| 160 | + |
| 161 | +<table class="variables-matrix input-arguments"> |
| 162 | + <thead> |
| 163 | + <tr> |
| 164 | + <th>Argument Name</th> |
| 165 | + <th>Type</th> |
| 166 | + <th>Description</th> |
| 167 | + <th>Default Value</th> |
| 168 | + <th>Required</th> |
| 169 | + </tr> |
| 170 | + </thead> |
| 171 | + <tbody> |
| 172 | + <tr> |
| 173 | + <td><strong>name</strong></td> |
| 174 | + <td> |
| 175 | + <a href="" class="label type-hint type-hint-string">string</a> |
| 176 | + </td> |
| 177 | + <td><p> The name of the Meteor method to run on the server side.</p> |
| 178 | + </td> |
| 179 | + <td></td> |
| 180 | + <td><a href="" class="label type-hint type-hint-object">Yes</a></td> |
| 181 | + </tr> |
| 182 | + <tr> |
| 183 | + <td>arguments...</td> |
| 184 | + <td> |
| 185 | + <a href="" class="label type-hint">Any</a> |
| 186 | + </td> |
| 187 | + <td><p> Argument that will be passed to the method. </p> |
| 188 | + </td> |
| 189 | + <td></td> |
| 190 | + <td><a href="" class="label type-hint type-hint-object">No</a></td> |
| 191 | + </tr> |
| 192 | + <tr> |
| 193 | + <td>resultCallback</td> |
| 194 | + <td> |
| 195 | + <a href="" class="label type-hint type-hint-function">function</a> |
| 196 | + </td> |
| 197 | + <td><p> Optional callback, which is called asynchronously with the error or result after the method is complete. If not provided, the method runs synchronously if possible (see below). |
| 198 | + </p> |
| 199 | + </td> |
| 200 | + <td></td> |
| 201 | + <td><a href="" class="label type-hint type-hint-object">No</a></td> |
| 202 | + </tr> |
| 203 | + </tbody> |
| 204 | +</table> |
| 205 | + |
12 | 206 |
|
13 | 207 | {{/markdown}}
|
14 | 208 |
|
|
0 commit comments