Skip to content

Commit

Permalink
feat(jsdoc): Added documentation and build version, and docs generati…
Browse files Browse the repository at this point in the history
…on script
  • Loading branch information
dotansimha committed Oct 31, 2016
1 parent 4b7391a commit 00e546a
Show file tree
Hide file tree
Showing 13 changed files with 1,246 additions and 3 deletions.
102 changes: 102 additions & 0 deletions dist/MeteorObservable.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,108 @@
import { Observable } from 'rxjs';
/**
* 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.
*
*/
export declare class MeteorObservable {
/**
* Method has the same notation as Meteor.call, only without the callbacks:
* MeteorObservable.call(name, [...args])
*
* @param {String} name - Name of the method in the Meteor server
* @param {any} args - Parameters that will be forwarded to the method.
* after the func call to initiate change detection.
* @returns {Observable<T>} - RxJS Observable, which completes when the server return a response.
* @example <caption>Example using Angular2 Component</caption>
* class MyComponent {
* constructor() {
*
* }
*
* doAction(payload) {
* MeteorObservable.call("myData", payload).subscribe((response) => {
* // Handle success and response from server!
* }, (err) => {
* // Handle error
* });
* }
* }
*/
static call<T>(name: string, ...args: any[]): Observable<T>;
/**
* Method has the same notation as Meteor.subscribe, only without the callbacks:
* subscribe(name, [...args])
*
* You can use this method from any Angular2 element - such as Component, Pipe or
* Service.
*
* @param {String} name - Name of the publication in the Meteor server
* @param {any} args - Parameters that will be forwarded to the publication.
* after the func call to initiate change detection.
* @returns {Observable} - RxJS Observable, which completes when the subscription is ready.
* @example <caption>Example using Angular2 Service</caption>
* class MyService {
* private meteorSubscription: Observable<any>;
*
* constructor() {
*
* }
*
* subscribeToData() {
* this.meteorSubscription = MeteorObservable.subscribe<any>("myData").subscribe(() => {
* // Subscription is ready!
* });
* }
*
* unsubscribeToData() {
* this.meteorSubscription.unsubscribe();
* }
* }
*
* @example <caption>Example using Angular2 Component</caption>
* class MyComponent implements OnInit, OnDestroy {
* private meteorSubscription: Observable<any>;
*
* constructor() {
*
* }
*
* ngOnInit() {
* this.meteorSubscription = MeteorObservable.subscribe("myData").subscribe(() => {
* // Subscription is ready!
* });
* }
*
* ngOnDestroy() {
* this.meteorSubscription.unsubscribe();
* }
* }
*
* @see {@link http://docs.meteor.com/api/pubsub.html|Publications in Meteor documentation}
*/
static subscribe<T>(name: string, ...args: any[]): Observable<T>;
/**
* Method has the same notation as Meteor.autorun, only without the callback:
* MeteorObservable.autorun()
*
* @returns {Observable<T>} - RxJS Observable, which trigger the subscription callback
* each time that Meteor Tracker detects a change.
* @example <caption>Example using Angular2 Component</caption>
* class MyComponent {
* constructor() {
*
* }
*
* doAction(payload) {
* MeteorObservable.autorun().subscribe(() => {
* // Handle Tracker autorun change
* });
* }
* }
*/
static autorun(): Observable<Tracker.Computation>;
}
102 changes: 102 additions & 0 deletions dist/MeteorObservable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,41 @@ import { isMeteorCallbacks, forkZone, removeObserver } from './utils';
function throwInvalidCallback(method) {
throw new Error("Invalid " + method + " arguments:\n your last param can't be a callback function, \n please remove it and use \".subscribe\" of the Observable!");
}
/**
* 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.
*
*/
export var MeteorObservable = (function () {
function MeteorObservable() {
}
/**
* Method has the same notation as Meteor.call, only without the callbacks:
* MeteorObservable.call(name, [...args])
*
* @param {String} name - Name of the method in the Meteor server
* @param {any} args - Parameters that will be forwarded to the method.
* after the func call to initiate change detection.
* @returns {Observable<T>} - RxJS Observable, which completes when the server return a response.
* @example <caption>Example using Angular2 Component</caption>
* class MyComponent {
* constructor() {
*
* }
*
* doAction(payload) {
* MeteorObservable.call("myData", payload).subscribe((response) => {
* // Handle success and response from server!
* }, (err) => {
* // Handle error
* });
* }
* }
*/
MeteorObservable.call = function (name) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
Expand All @@ -29,6 +61,57 @@ export var MeteorObservable = (function () {
])));
});
};
/**
* Method has the same notation as Meteor.subscribe, only without the callbacks:
* subscribe(name, [...args])
*
* You can use this method from any Angular2 element - such as Component, Pipe or
* Service.
*
* @param {String} name - Name of the publication in the Meteor server
* @param {any} args - Parameters that will be forwarded to the publication.
* after the func call to initiate change detection.
* @returns {Observable} - RxJS Observable, which completes when the subscription is ready.
* @example <caption>Example using Angular2 Service</caption>
* class MyService {
* private meteorSubscription: Observable<any>;
*
* constructor() {
*
* }
*
* subscribeToData() {
* this.meteorSubscription = MeteorObservable.subscribe<any>("myData").subscribe(() => {
* // Subscription is ready!
* });
* }
*
* unsubscribeToData() {
* this.meteorSubscription.unsubscribe();
* }
* }
*
* @example <caption>Example using Angular2 Component</caption>
* class MyComponent implements OnInit, OnDestroy {
* private meteorSubscription: Observable<any>;
*
* constructor() {
*
* }
*
* ngOnInit() {
* this.meteorSubscription = MeteorObservable.subscribe("myData").subscribe(() => {
* // Subscription is ready!
* });
* }
*
* ngOnDestroy() {
* this.meteorSubscription.unsubscribe();
* }
* }
*
* @see {@link http://docs.meteor.com/api/pubsub.html|Publications in Meteor documentation}
*/
MeteorObservable.subscribe = function (name) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
Expand Down Expand Up @@ -67,6 +150,25 @@ export var MeteorObservable = (function () {
};
});
};
/**
* Method has the same notation as Meteor.autorun, only without the callback:
* MeteorObservable.autorun()
*
* @returns {Observable<T>} - RxJS Observable, which trigger the subscription callback
* each time that Meteor Tracker detects a change.
* @example <caption>Example using Angular2 Component</caption>
* class MyComponent {
* constructor() {
*
* }
*
* doAction(payload) {
* MeteorObservable.autorun().subscribe(() => {
* // Handle Tracker autorun change
* });
* }
* }
*/
MeteorObservable.autorun = function () {
var zone = forkZone();
var observers = [];
Expand Down
123 changes: 122 additions & 1 deletion dist/ObservableCollection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,136 @@ export declare module MongoObservable {
fetch?: string[];
transform?: Function;
}
function fromExisting<T>(collection: Mongo.Collection<T>): Collection<T>;
/**
* Creates a new MongoObservable.Collection from an existing of predefined Mongo.Collection.
* Use this feature to wrap existing collections such as Meteor.users.
* @param {Mongo.Collection} collection - The collection.
* @returns {MongoObservable.Collection} - Wrapped collection.
* @static
*/
function fromExisting<T>(collection: Mongo.Collection<T>): MongoObservable.Collection<T>;
/**
* 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.
*/
class Collection<T> {
private _collection;
/**
* Creates a new Mongo.Collection instance wrapped with Observable features.
* @param {String | Mongo.Collection} nameOrExisting - 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.
* @param {ConstructorOptions} options - Creation options.
* @constructor
*/
constructor(nameOrExisting: string | Mongo.Collection<T>, options?: ConstructorOptions);
/**
* Returns the Mongo.Collection object that wrapped with the MongoObservable.Collection.
* @returns {Mongo.Collection<T>} The Collection instance
*/
readonly collection: Mongo.Collection<T>;
/**
* Allow users to write directly to this collection from client code, subject to limitations you define.
*
* @returns {Boolean}
*/
allow(options: AllowDenyOptionsObject<T>): boolean;
/**
* Override allow rules.
*
* @returns {Boolean}
*/
deny(options: AllowDenyOptionsObject<T>): boolean;
/**
* Returns the Collection object corresponding to this collection from the npm
* mongodb driver module which is wrapped by Mongo.Collection.
*
* @returns {Mongo.Collection} The Collection instance
*
* @see {@link https://docs.meteor.com/api/collections.html#Mongo-Collection-rawCollection|rawCollection on Meteor documentation}
*/
rawCollection(): any;
/**
* Returns the Db object corresponding to this collection's database connection from the
* npm mongodb driver module which is wrapped by Mongo.Collection.
*
* @returns {Mongo.Db} The Db instance
*
* @see {@link https://docs.meteor.com/api/collections.html#Mongo-Collection-rawDatabase|rawDatabase on Meteor documentation}
*/
rawDatabase(): any;
/**
* Insert a document in the collection.
*
* @param {T} doc - The document to insert. May not yet have an _id
* attribute, in which case Meteor will generate one for you.
* @returns {Observable<string>} Observable which completes with the inserted ObjectId
*
* @see {@link https://docs.meteor.com/api/collections.html#Mongo-Collection-insert|insert on Meteor documentation}
*/
insert(doc: T): Observable<string>;
/**
* Remove documents from the collection.
*
* @param {Collection~MongoQuerySelector} selector - Specifies which documents to modify
* @returns {Observable<Number>} Observable which completes with the number of affected rows
*
* @see {@link https://docs.meteor.com/api/collections.html#Mongo-Collection-remove|remove on Meteor documentation}
*/
remove(selector: Selector | ObjectID | string): Observable<number>;
/**
* Modify one or more documents in the collection.
*
* @param {Collection~MongoQuerySelector} selector - Specifies which documents to modify
* @param {Modifier} modifier - Specifies how to modify the documents
* @param {MongoUpdateOptions} options - Update options
* first argument and, if no error, the number of affected documents as the second
* @returns {Observable<Number>} Observable which completes with the number of affected rows
*
* @see {@link https://docs.meteor.com/api/collections.html#Mongo-Collection-update|update on Meteor documentation}
*/
update(selector: Selector | ObjectID | string, modifier: Modifier, options?: {
multi?: boolean;
upsert?: boolean;
}): Observable<number>;
/**
* Finds the first document that matches the selector, as ordered by sort and skip options.
*
* @param {Collection~MongoQuerySelector} selector - Specifies which documents to modify
* @param {Modifier} modifier - Specifies how to modify the documents
* @param {MongoUpsertOptions} options - Upsert options
* first argument and, if no error, the number of affected documents as the second.
* @returns {Observable<{numberAffected, insertedId}>} Observable which completes with an
* Object that contain the keys numberAffected and insertedId.
*
* @see {@link https://docs.meteor.com/api/collections.html#Mongo-Collection-upsert|upsert on Meteor documentation}
*/
upsert(selector: Selector | ObjectID | string, modifier: Modifier, options?: {
multi?: boolean;
}): Observable<number>;
/**
* Method has the same notation as Mongo.Collection.find, only returns Observable.
*
* @param {Collection~MongoQuerySelector} selector - A query describing the documents to find
* @param {Collection~MongoQueryOptions} options - Query options, such as sort, limit, etc.
* @returns {ObservableCursor<T>} RxJS Observable wrapped with Meteor features.
* @example <caption>Using Angular2 Component</caption>
* const MyCollection = MongoObservable.Collection("myCollection");
*
* class MyComponent {
* private myData: ObservableCursor<any>;
*
* constructor() {
* this.myData = MyCollection.find({}, {limit: 10});
* }
* }
*
* @see {@link https://docs.meteor.com/api/collections.html#Mongo-Collection-find|find on Meteor documentation}
*/
find(selector?: Selector | ObjectID | string, options?: {
sort?: SortSpecifier;
skip?: number;
Expand All @@ -44,6 +156,15 @@ export declare module MongoObservable {
reactive?: boolean;
transform?: Function;
}): ObservableCursor<T>;
/**
* Finds the first document that matches the selector, as ordered by sort and skip options.
*
* @param {Collection~MongoQuerySelector} selector - A query describing the documents to find
* @param {Collection~MongoQueryOptions} options - Query options, such as sort, limit, etc.
* @returns {any} The first object, or `undefined` in case of non-existing object.
*
* @see {@link https://docs.meteor.com/api/collections.html#Mongo-Collection-findOne|findOne on Meteor documentation}
*/
findOne(selector?: Selector | ObjectID | string, options?: {
sort?: SortSpecifier;
skip?: number;
Expand Down
Loading

0 comments on commit 00e546a

Please sign in to comment.