diff --git a/docs/MeteorObservable.md b/docs/MeteorObservable.md index 7ff6a3f2..9c5c59af 100644 --- a/docs/MeteorObservable.md +++ b/docs/MeteorObservable.md @@ -1,122 +1,132 @@ - + -## 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) ⇒ Tracker.Computation - * [.subscribe(name, ...args, autoBind)](#MeteorComponent+subscribe) ⇒ Meteor.SubscriptionHandle - * [.call(name, ...args, autoBind)](#MeteorComponent+call) ⇒ void - * _inner_ - * [~autorunCallback](#MeteorComponent..autorunCallback) : function +* [MeteorObservable](#MeteorObservable) + * [.call(name, ...args)](#MeteorObservable.call) ⇒ Observable.<T> + * [.subscribe(name, ...args)](#MeteorObservable.subscribe) ⇒ Observable + * [.autorun()](#MeteorObservable.autorun) ⇒ Observable.<T> - + -### meteorComponent.autorun(func, autoBind) ⇒ Tracker.Computation -Method has the same notation as Meteor.autorun -except the last parameter. +### MeteorObservable.call(name, ...args) ⇒ Observable.<T> +Method has the same notation as Meteor.call, only without the callbacks: + MeteorObservable.call(name, [...args]) -**Kind**: instance method of [MeteorComponent](#MeteorComponent) -**Returns**: Tracker.Computation - - Object representing the Meteor computation -**See** +**Kind**: static method of [MeteorObservable](#MeteorObservable) +**Returns**: Observable.<T> - - 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 | String | Name of the method in the Meteor server | +| ...args | any | 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 | [autorunCallback](#MeteorComponent..autorunCallback) | | Callback to be executed when current computation is invalidated. The Tracker.Computation object will be passed as argument to this callback. | -| autoBind | Boolean | true | 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 + }); + } + } ``` - + -### meteorComponent.subscribe(name, ...args, autoBind) ⇒ Meteor.SubscriptionHandle -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) ⇒ Observable +Method has the same notation as Meteor.subscribe, only without the callbacks: + subscribe(name, [...args]) -**Kind**: instance method of [MeteorComponent](#MeteorComponent) -**Returns**: Meteor.SubscriptionHandle - - 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 [MeteorObservable](#MeteorObservable) +**Returns**: Observable - - 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 | String | Name of the publication in the Meteor server | -| ...args | any | Parameters that will be forwarded to the publication. | -| autoBind | Boolean | Determine whether Angular 2 zone will run after the func call to initiate change detection. | +| ...args | any | 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; + constructor() { - super(); - this.subscribe("myData", 10); + } + + subscribeToData() { + this.meteorSubscription = MeteorObservable.subscribe("myData").subscribe(() => { + // Subscription is ready! + }); + } + + unsubscribeToData() { + this.meteorSubscription.unsubscribe(); } } ``` - - -### meteorComponent.call(name, ...args, autoBind) ⇒ void -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; -**Kind**: instance method of [MeteorComponent](#MeteorComponent) + constructor() { -| Param | Type | Description | -| --- | --- | --- | -| name | String | Name of the publication in the Meteor server | -| ...args | any | Parameters that will be forwarded to the method. | -| autoBind | Boolean | 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(); } } ``` - + -### MeteorComponent~autorunCallback : function -This callback called when autorun triggered by Meteor. +### MeteorObservable.autorun() ⇒ Observable.<T> +Method has the same notation as Meteor.autorun, only without the callback: + MeteorObservable.autorun() -**Kind**: inner typedef of [MeteorComponent](#MeteorComponent) +**Kind**: static method of [MeteorObservable](#MeteorObservable) +**Returns**: Observable.<T> - - 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 | Tracker.Computation | + } + doAction(payload) { + MeteorObservable.autorun().subscribe(() => { + // Handle Tracker autorun change + }); + } + } +``` diff --git a/docs/ObservableCollection.md b/docs/ObservableCollection.md index 7ff6a3f2..1e74116d 100644 --- a/docs/ObservableCollection.md +++ b/docs/ObservableCollection.md @@ -1,122 +1,224 @@ - + -## 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. +## Collection +A class represents a MongoDB collection in the client side, wrapped with RxJS +Observables, so you can use it with your Angular 2 easier. +The wrapper has the same API as Mongo.Collection, only the "find" method returns +an ObservableCursor instead of regular Mongo.Cursor. + +T is a generic type - should be used with the type of the objects inside the collection. **Kind**: global class -* [MeteorComponent](#MeteorComponent) +* [Collection](#Collection) + * [new Collection(nameOrExisting, options)](#new_Collection_new) * _instance_ - * [.autorun(func, autoBind)](#MeteorComponent+autorun) ⇒ Tracker.Computation - * [.subscribe(name, ...args, autoBind)](#MeteorComponent+subscribe) ⇒ Meteor.SubscriptionHandle - * [.call(name, ...args, autoBind)](#MeteorComponent+call) ⇒ void + * [.collection](#Collection+collection) ⇒ Mongo.Collection.<T> + * [.allow()](#Collection+allow) ⇒ Boolean + * [.deny()](#Collection+deny) ⇒ Boolean + * [.rawCollection()](#Collection+rawCollection) ⇒ Mongo.Collection + * [.rawDatabase()](#Collection+rawDatabase) ⇒ Mongo.Db + * [.insert(doc)](#Collection+insert) ⇒ Observable.<string> + * [.remove(selector)](#Collection+remove) ⇒ Observable.<Number> + * [.update(selector, modifier, options)](#Collection+update) ⇒ Observable.<Number> + * [.upsert(selector, modifier, options)](#Collection+upsert) ⇒ Observable.<{numberAffected, insertedId}> + * [.find(selector, options)](#Collection+find) ⇒ ObservableCursor.<T> + * [.findOne(selector, options)](#Collection+findOne) ⇒ any * _inner_ - * [~autorunCallback](#MeteorComponent..autorunCallback) : function + * [~MongoQueryOptions](#Collection..MongoQueryOptions) : Object + * [~MongoQuerySelector](#Collection..MongoQuerySelector) : Mongo.Selector | Mongo.ObjectID | string + * [~MongoUpsertOptions](#Collection..MongoUpsertOptions) : Object + * [~MongoUpdateOptions](#Collection..MongoUpdateOptions) : Object - + -### meteorComponent.autorun(func, autoBind) ⇒ Tracker.Computation -Method has the same notation as Meteor.autorun -except the last parameter. +### new Collection(nameOrExisting, options) +Creates a new Mongo.Collection instance wrapped with Observable features. -**Kind**: instance method of [MeteorComponent](#MeteorComponent) -**Returns**: Tracker.Computation - - Object representing the Meteor computation -**See** -- [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 | +| --- | --- | --- | +| nameOrExisting | String | Mongo.Collection | The name of the collection. If null, creates an unmanaged (unsynchronized) local collection. If provided an instance of existing collection, will create a wrapper for the existing Mongo.Collection. | +| options | ConstructorOptions | Creation options. | + -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| func | [autorunCallback](#MeteorComponent..autorunCallback) | | Callback to be executed when current computation is invalidated. The Tracker.Computation object will be passed as argument to this callback. | -| autoBind | Boolean | true | Determine whether Angular2 Zone will run after the func call to initiate change detection. | +### collection.collection ⇒ Mongo.Collection.<T> +Returns the Mongo.Collection object that wrapped with the MongoObservable.Collection. -**Example** -```js -class MyComponent extends MeteorComponent { - private myData: Mongo.Cursor; - private dataId: any; - - constructor() { - super(); - - this.autorun(() => { - this.myData = MyCollection.find({ _id: dataId}); - }, true); - } -} -``` - +**Kind**: instance property of [Collection](#Collection) +**Returns**: Mongo.Collection.<T> - The Collection instance + + +### collection.allow() ⇒ Boolean +Allow users to write directly to this collection from client code, subject to limitations you define. + +**Kind**: instance method of [Collection](#Collection) + + +### collection.deny() ⇒ Boolean +Override allow rules. -### meteorComponent.subscribe(name, ...args, autoBind) ⇒ Meteor.SubscriptionHandle -Method has the same notation as Meteor.subscribe: - subscribe(name, [args1, args2], [callbacks], [autoBind]) - except the last autoBind param (see autorun above). +**Kind**: instance method of [Collection](#Collection) + -**Kind**: instance method of [MeteorComponent](#MeteorComponent) -**Returns**: Meteor.SubscriptionHandle - - The handle of the subscription created by Meteor. -**See**: [Publication/Subscription in Meteor documentation](http://docs.meteor.com/api/pubsub.html) +### collection.rawCollection() ⇒ Mongo.Collection +Returns the Collection object corresponding to this collection from the npm + mongodb driver module which is wrapped by Mongo.Collection. + +**Kind**: instance method of [Collection](#Collection) +**Returns**: Mongo.Collection - The Collection instance +**See**: [rawCollection on Meteor documentation](https://docs.meteor.com/api/collections.html#Mongo-Collection-rawCollection) + + +### collection.rawDatabase() ⇒ Mongo.Db +Returns the Db object corresponding to this collection's database connection from the + npm mongodb driver module which is wrapped by Mongo.Collection. + +**Kind**: instance method of [Collection](#Collection) +**Returns**: Mongo.Db - The Db instance +**See**: [rawDatabase on Meteor documentation](https://docs.meteor.com/api/collections.html#Mongo-Collection-rawDatabase) + + +### collection.insert(doc) ⇒ Observable.<string> +Insert a document in the collection. + +**Kind**: instance method of [Collection](#Collection) +**Returns**: Observable.<string> - Observable which completes with the inserted ObjectId +**See**: [insert on Meteor documentation](https://docs.meteor.com/api/collections.html#Mongo-Collection-insert) | Param | Type | Description | | --- | --- | --- | -| name | String | Name of the publication in the Meteor server | -| ...args | any | Parameters that will be forwarded to the publication. | -| autoBind | Boolean | Determine whether Angular 2 zone will run after the func call to initiate change detection. | +| doc | T | The document to insert. May not yet have an _id attribute, in which case Meteor will generate one for you. | -**Example** -```js -class MyComponent extends MeteorComponent { - constructor() { - super(); + - this.subscribe("myData", 10); - } - } +### collection.remove(selector) ⇒ Observable.<Number> +Remove documents from the collection. - -``` - +**Kind**: instance method of [Collection](#Collection) +**Returns**: Observable.<Number> - Observable which completes with the number of affected rows +**See**: [remove on Meteor documentation](https://docs.meteor.com/api/collections.html#Mongo-Collection-remove) + +| Param | Type | Description | +| --- | --- | --- | +| selector | [MongoQuerySelector](#Collection..MongoQuerySelector) | Specifies which documents to modify | + + -### meteorComponent.call(name, ...args, autoBind) ⇒ void -Method has the same notation as Meteor.call: - call(name, [args1, args2], [callbacks], [autoBind]) - except the last autoBind param (see autorun above). +### collection.update(selector, modifier, options) ⇒ Observable.<Number> +Modify one or more documents in the collection. -**Kind**: instance method of [MeteorComponent](#MeteorComponent) +**Kind**: instance method of [Collection](#Collection) +**Returns**: Observable.<Number> - Observable which completes with the number of affected rows +**See**: [update on Meteor documentation](https://docs.meteor.com/api/collections.html#Mongo-Collection-update) | Param | Type | Description | | --- | --- | --- | -| name | String | Name of the publication in the Meteor server | -| ...args | any | Parameters that will be forwarded to the method. | -| autoBind | Boolean | autoBind Determine whether Angular 2 zone will run after the func call to initiate change detection. | +| selector | [MongoQuerySelector](#Collection..MongoQuerySelector) | Specifies which documents to modify | +| modifier | Modifier | Specifies how to modify the documents | +| options | MongoUpdateOptions | Update options first argument and, if no error, the number of affected documents as the second | + + + +### collection.upsert(selector, modifier, options) ⇒ Observable.<{numberAffected, insertedId}> +Finds the first document that matches the selector, as ordered by sort and skip options. + +**Kind**: instance method of [Collection](#Collection) +**Returns**: Observable.<{numberAffected, insertedId}> - Observable which completes with an + Object that contain the keys numberAffected and insertedId. +**See**: [upsert on Meteor documentation](https://docs.meteor.com/api/collections.html#Mongo-Collection-upsert) + +| Param | Type | Description | +| --- | --- | --- | +| selector | [MongoQuerySelector](#Collection..MongoQuerySelector) | Specifies which documents to modify | +| modifier | Modifier | Specifies how to modify the documents | +| options | MongoUpsertOptions | Upsert options first argument and, if no error, the number of affected documents as the second. | + + -**Example** +### collection.find(selector, options) ⇒ ObservableCursor.<T> +Method has the same notation as Mongo.Collection.find, only returns Observable. + +**Kind**: instance method of [Collection](#Collection) +**Returns**: ObservableCursor.<T> - RxJS Observable wrapped with Meteor features. +**See**: [find on Meteor documentation](https://docs.meteor.com/api/collections.html#Mongo-Collection-find) + +| Param | Type | Description | +| --- | --- | --- | +| selector | [MongoQuerySelector](#Collection..MongoQuerySelector) | A query describing the documents to find | +| options | [MongoQueryOptions](#Collection..MongoQueryOptions) | Query options, such as sort, limit, etc. | + +**Example** *(Using Angular2 Component)* ```js -class MyComponent extends MeteorComponent { - constructor() { - super(); + const MyCollection = MongoObservable.Collection("myCollection"); + + class MyComponent { + private myData: ObservableCursor; - this.call("serverMethod", (err, result) => { - // Handle response... - }); + constructor() { + this.myData = MyCollection.find({}, {limit: 10}); } } - - ``` - + + +### collection.findOne(selector, options) ⇒ any +Finds the first document that matches the selector, as ordered by sort and skip options. + +**Kind**: instance method of [Collection](#Collection) +**Returns**: any - The first object, or `undefined` in case of non-existing object. +**See**: [findOne on Meteor documentation](https://docs.meteor.com/api/collections.html#Mongo-Collection-findOne) + +| Param | Type | Description | +| --- | --- | --- | +| selector | [MongoQuerySelector](#Collection..MongoQuerySelector) | A query describing the documents to find | +| options | [MongoQueryOptions](#Collection..MongoQueryOptions) | Query options, such as sort, limit, etc. | -### MeteorComponent~autorunCallback : function -This callback called when autorun triggered by Meteor. + -**Kind**: inner typedef of [MeteorComponent](#MeteorComponent) +### Collection~MongoQueryOptions : Object +An options object for MongoDB queries. -| Param | Type | -| --- | --- | -| computation | Tracker.Computation | +**Kind**: inner typedef of [Collection](#Collection) +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| sort | Object | Sort order (default: natural order) | +| skip | Number | Number of results to skip at the beginning | +| fields | Object | Dictionary of fields to return or exclude. | +| reactive | Boolean | (Client only) Default true; pass false to disable reactivity | +| transform | function | Overrides transform on the Collection for this cursor. Pass null to disable transformation. | + + + +### Collection~MongoQuerySelector : Mongo.Selector | Mongo.ObjectID | string +A MongoDB query selector representation. + +**Kind**: inner typedef of [Collection](#Collection) + + +### Collection~MongoUpsertOptions : Object +A MongoDB query options for upsert action + +**Kind**: inner typedef of [Collection](#Collection) +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| multi | Boolean | True to modify all matching documents; false to only modify one of the matching documents (the default). | + + + +### Collection~MongoUpdateOptions : Object +A MongoDB query options for update action + +**Kind**: inner typedef of [Collection](#Collection) +**Properties** + +| Name | Type | Description | +| --- | --- | --- | +| multi | Boolean | True to modify all matching documents; | +| upsert | Boolean | True to use upsert logic. | diff --git a/docs/ObservableCursor.md b/docs/ObservableCursor.md index 7ff6a3f2..c903f271 100644 --- a/docs/ObservableCursor.md +++ b/docs/ObservableCursor.md @@ -1,122 +1,218 @@ - +## Classes -## 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. +
+
ObservableCursorObservable
+

A class represents a Monog.Cursor wrapped with RxJS features.

+
+
ObservableCursorObservable
+
+
+ + + +## ObservableCursor ⇐ Observable +A class represents a Monog.Cursor wrapped with RxJS features. **Kind**: global class +**Extends:** Observable -* [MeteorComponent](#MeteorComponent) +* [ObservableCursor](#ObservableCursor) ⇐ Observable + * [new ObservableCursor(cursor)](#new_ObservableCursor_new) * _instance_ - * [.autorun(func, autoBind)](#MeteorComponent+autorun) ⇒ Tracker.Computation - * [.subscribe(name, ...args, autoBind)](#MeteorComponent+subscribe) ⇒ Meteor.SubscriptionHandle - * [.call(name, ...args, autoBind)](#MeteorComponent+call) ⇒ void - * _inner_ - * [~autorunCallback](#MeteorComponent..autorunCallback) : function + * [.cursor](#ObservableCursor+cursor) ⇒ Mongo.Cursor.<T> + * [.collectionCount()](#ObservableCursor+collectionCount) ⇒ Observable + * [.stop()](#ObservableCursor+stop) + * [.dispose()](#ObservableCursor+dispose) + * [.fetch()](#ObservableCursor+fetch) ⇒ Array.<T> + * [.observe(callbacks)](#ObservableCursor+observe) ⇒ Meteor.LiveQueryHandle + * [.observeChanges(callbacks)](#ObservableCursor+observeChanges) ⇒ Meteor.LiveQueryHandle + * _static_ + * [.create(cursor)](#ObservableCursor.create) ⇒ ObservableCursor.<T> + + + +### new ObservableCursor(cursor) + +| Param | Type | Description | +| --- | --- | --- | +| cursor | Mongo.Cursor.<T> | The Mongo.Cursor to wrap. | + + + +### observableCursor.cursor ⇒ Mongo.Cursor.<T> +Returns the actual Mongo.Cursor that wrapped by current ObservableCursor instance. + +**Kind**: instance property of [ObservableCursor](#ObservableCursor) +**Returns**: Mongo.Cursor.<T> - The actual MongoDB Cursor. + + +### observableCursor.collectionCount() ⇒ Observable +A wrapper for Mongo.Cursor.count() method - returns an Observable of number, which +triggers each time there is a change in the collection, and exposes the number of +objects in the collection. + +**Kind**: instance method of [ObservableCursor](#ObservableCursor) +**Returns**: Observable - Observable which trigger the callback when the +count of the object changes. + + +### observableCursor.stop() +Stops the observation on the cursor. - +**Kind**: instance method of [ObservableCursor](#ObservableCursor) + -### meteorComponent.autorun(func, autoBind) ⇒ Tracker.Computation -Method has the same notation as Meteor.autorun -except the last parameter. +### observableCursor.dispose() +Clears the Observable definition. +Use this method only when the Observable is still cold, and there are no active subscriptions yet. -**Kind**: instance method of [MeteorComponent](#MeteorComponent) -**Returns**: Tracker.Computation - - Object representing the Meteor computation -**See** +**Kind**: instance method of [ObservableCursor](#ObservableCursor) + -- [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) +### observableCursor.fetch() ⇒ Array.<T> +Return all matching documents as an Array. +**Kind**: instance method of [ObservableCursor](#ObservableCursor) +**Returns**: Array.<T> - The array with the matching documents. + -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| func | [autorunCallback](#MeteorComponent..autorunCallback) | | Callback to be executed when current computation is invalidated. The Tracker.Computation object will be passed as argument to this callback. | -| autoBind | Boolean | true | Determine whether Angular2 Zone will run after the func call to initiate change detection. | +### observableCursor.observe(callbacks) ⇒ Meteor.LiveQueryHandle +Watch a query. Receive callbacks as the result set changes. -**Example** -```js -class MyComponent extends MeteorComponent { - private myData: Mongo.Cursor; - private dataId: any; +**Kind**: instance method of [ObservableCursor](#ObservableCursor) +**Returns**: Meteor.LiveQueryHandle - The array with the matching documents. - constructor() { - super(); +| Param | Type | Description | +| --- | --- | --- | +| callbacks | Mongo.ObserveCallbacks | The callbacks object. | - this.autorun(() => { - this.myData = MyCollection.find({ _id: dataId}); - }, true); - } -} -``` - + -### meteorComponent.subscribe(name, ...args, autoBind) ⇒ Meteor.SubscriptionHandle -Method has the same notation as Meteor.subscribe: - subscribe(name, [args1, args2], [callbacks], [autoBind]) - except the last autoBind param (see autorun above). +### observableCursor.observeChanges(callbacks) ⇒ Meteor.LiveQueryHandle +Watch a query. Receive callbacks as the result set changes. +Only the differences between the old and new documents are passed to the callbacks. -**Kind**: instance method of [MeteorComponent](#MeteorComponent) -**Returns**: Meteor.SubscriptionHandle - - The handle of the subscription created by Meteor. -**See**: [Publication/Subscription in Meteor documentation](http://docs.meteor.com/api/pubsub.html) +**Kind**: instance method of [ObservableCursor](#ObservableCursor) +**Returns**: Meteor.LiveQueryHandle - The array with the matching documents. | Param | Type | Description | | --- | --- | --- | -| name | String | Name of the publication in the Meteor server | -| ...args | any | Parameters that will be forwarded to the publication. | -| autoBind | Boolean | Determine whether Angular 2 zone will run after the func call to initiate change detection. | +| callbacks | Mongo.ObserveChangesCallbacks | The callbacks object. | + + + +### ObservableCursor.create(cursor) ⇒ ObservableCursor.<T> +Static method which creates an ObservableCursor from Mongo.Cursor. + Use this to create an ObservableCursor object from an existing Mongo.Cursor. + Prefer to create an Cursors from the ObservableCollection instance instead. + +**Kind**: static method of [ObservableCursor](#ObservableCursor) +**Returns**: ObservableCursor.<T> - Wrapped Cursor. + +| Param | Type | Description | +| --- | --- | --- | +| cursor | Mongo.Cursor.<T> | The Mongo.Cursor to wrap. | + + + +## ObservableCursor ⇐ Observable +**Kind**: global class +**Extends:** Observable + +* [ObservableCursor](#ObservableCursor) ⇐ Observable + * [new ObservableCursor(cursor)](#new_ObservableCursor_new) + * _instance_ + * [.cursor](#ObservableCursor+cursor) ⇒ Mongo.Cursor.<T> + * [.collectionCount()](#ObservableCursor+collectionCount) ⇒ Observable + * [.stop()](#ObservableCursor+stop) + * [.dispose()](#ObservableCursor+dispose) + * [.fetch()](#ObservableCursor+fetch) ⇒ Array.<T> + * [.observe(callbacks)](#ObservableCursor+observe) ⇒ Meteor.LiveQueryHandle + * [.observeChanges(callbacks)](#ObservableCursor+observeChanges) ⇒ Meteor.LiveQueryHandle + * _static_ + * [.create(cursor)](#ObservableCursor.create) ⇒ ObservableCursor.<T> -**Example** -```js -class MyComponent extends MeteorComponent { - constructor() { - super(); + - this.subscribe("myData", 10); - } - } +### new ObservableCursor(cursor) + +| Param | Type | Description | +| --- | --- | --- | +| cursor | Mongo.Cursor.<T> | The Mongo.Cursor to wrap. | + + + +### observableCursor.cursor ⇒ Mongo.Cursor.<T> +Returns the actual Mongo.Cursor that wrapped by current ObservableCursor instance. + +**Kind**: instance property of [ObservableCursor](#ObservableCursor) +**Returns**: Mongo.Cursor.<T> - The actual MongoDB Cursor. + + +### observableCursor.collectionCount() ⇒ Observable +A wrapper for Mongo.Cursor.count() method - returns an Observable of number, which +triggers each time there is a change in the collection, and exposes the number of +objects in the collection. + +**Kind**: instance method of [ObservableCursor](#ObservableCursor) +**Returns**: Observable - Observable which trigger the callback when the +count of the object changes. + + +### observableCursor.stop() +Stops the observation on the cursor. + +**Kind**: instance method of [ObservableCursor](#ObservableCursor) + + +### observableCursor.dispose() +Clears the Observable definition. +Use this method only when the Observable is still cold, and there are no active subscriptions yet. + +**Kind**: instance method of [ObservableCursor](#ObservableCursor) + + +### observableCursor.fetch() ⇒ Array.<T> +Return all matching documents as an Array. + +**Kind**: instance method of [ObservableCursor](#ObservableCursor) +**Returns**: Array.<T> - The array with the matching documents. + + +### observableCursor.observe(callbacks) ⇒ Meteor.LiveQueryHandle +Watch a query. Receive callbacks as the result set changes. + +**Kind**: instance method of [ObservableCursor](#ObservableCursor) +**Returns**: Meteor.LiveQueryHandle - The array with the matching documents. + +| Param | Type | Description | +| --- | --- | --- | +| callbacks | Mongo.ObserveCallbacks | The callbacks object. | + + + +### observableCursor.observeChanges(callbacks) ⇒ Meteor.LiveQueryHandle +Watch a query. Receive callbacks as the result set changes. +Only the differences between the old and new documents are passed to the callbacks. + +**Kind**: instance method of [ObservableCursor](#ObservableCursor) +**Returns**: Meteor.LiveQueryHandle - The array with the matching documents. + +| Param | Type | Description | +| --- | --- | --- | +| callbacks | Mongo.ObserveChangesCallbacks | The callbacks object. | - -``` - + -### meteorComponent.call(name, ...args, autoBind) ⇒ void -Method has the same notation as Meteor.call: - call(name, [args1, args2], [callbacks], [autoBind]) - except the last autoBind param (see autorun above). +### ObservableCursor.create(cursor) ⇒ ObservableCursor.<T> +Static method which creates an ObservableCursor from Mongo.Cursor. + Use this to create an ObservableCursor object from an existing Mongo.Cursor. + Prefer to create an Cursors from the ObservableCollection instance instead. -**Kind**: instance method of [MeteorComponent](#MeteorComponent) +**Kind**: static method of [ObservableCursor](#ObservableCursor) +**Returns**: ObservableCursor.<T> - Wrapped Cursor. | Param | Type | Description | | --- | --- | --- | -| name | String | Name of the publication in the Meteor server | -| ...args | any | Parameters that will be forwarded to the method. | -| autoBind | Boolean | autoBind Determine whether Angular 2 zone will run after the func call to initiate change detection. | - -**Example** -```js -class MyComponent extends MeteorComponent { - constructor() { - super(); - - this.call("serverMethod", (err, result) => { - // Handle response... - }); - } - } - - -``` - - -### MeteorComponent~autorunCallback : function -This callback called when autorun triggered by Meteor. - -**Kind**: inner typedef of [MeteorComponent](#MeteorComponent) - -| Param | Type | -| --- | --- | -| computation | Tracker.Computation | +| cursor | Mongo.Cursor.<T> | The Mongo.Cursor to wrap. | diff --git a/generate-docs.sh b/generate-docs.sh index 70b3f787..ee783ba0 100755 --- a/generate-docs.sh +++ b/generate-docs.sh @@ -1,3 +1,6 @@ -$(npm bin)/jsdoc2md -l js --source "$(cat ./src/MeteorObservable.ts)" > ./docs/MeteorObservable.md -$(npm bin)/jsdoc2md -l js --source "$(cat ./src/ObservableCollection.ts)" > ./docs/ObservableCollection.md -$(npm bin)/jsdoc2md -l js --source "$(cat ./src/ObservableCursor.ts)" > ./docs/ObservableCursor.md \ No newline at end of file +mkdir temp +tsc --outDir ./temp/ --target es6 +$(npm bin)/jsdoc2md -l js --no-cache --source "$(cat ./temp/MeteorObservable.js)" > ./docs/MeteorObservable.md +$(npm bin)/jsdoc2md -l js --no-cache --source "$(cat ./temp/ObservableCollection.js)" > ./docs/ObservableCollection.md +$(npm bin)/jsdoc2md -l js --no-cache --source "$(cat ./temp/ObservableCursor.js)" > ./docs/ObservableCursor.md +rm -rf temp &> /dev/null \ No newline at end of file