• Stars
    star
    120
  • Rank 285,534 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Exposing Mongo Cursor as RxJS Observable

Meteor + RxJS

npm version Build Status bitHound Overall Score bitHound Code bitHound Dev Dependencies

Harness Meteor reactivity with RxJS.

RxJS is built to simplify complexity dealing with reactive data flows. At the same time, Meteor's Minimongo cursors are a good target for RxJS API due to their reactivity. Thus, combining RxJS and Meteor, we bring together best parts of two worlds.

API Documentation

API documentation is available inside this repository, here.

Mongo Cursor Observable

As soon as you install this package (npm install meteor-rxjs), you have ability to use a special Mongo collection class that works with cursor observables instead of the ordinary Mongo cursors. In other words, one can subscribe on the Mongo cursor's data updates now as follows:

import {MongoObservable} from 'meteor-rxjs';

const Tasks = new MongoObservable.Collection<Task>('tasks');

Tasks.find({checked: false})
  .map(tasks => tasks.length)
  .subscribe(todoCount => console.log(todoCount));

Since this cursor observable is of RxJS’s type, every other methods and operators available to the observables as part of the RxJS API are also now available to the users, e.g., one can debounce data updates using RxJS’s debouncing operator:

import {Observable} from 'rxjs';

import {debounce, map} from 'rxjs/operators';

Tasks.find({checked: false})
  .pipe(debounce(() => Observable.interval(50)))
  .pipe(map(tasks => tasks.length))
  .subscribe(todoCount => console.log(todoCount));

Usage with Meteor packages

Meteor has a lot of packages that extend Mongo.Collection with new methods. Since MongoObservable.Collection is a wrapper over Mongo.Collection, you can't use new methods on observable instances directly. The solution here is to pass Mongo.Collection's instance to the observable constructor, and use them whenever you need after separately:

let collection = new Mongo.Collection('foo');
let observable = new MongoObservable.Collection(collection);
collection.attachSchema(...); // with SimpleSchema package

Usage in Angular

Angular has tight integration with RxJS since Angular is desinged to support reactive UI updates. One of the realizations of this integration is AsyncPipe, which is supposed to be used with RxJS observables.

In order to subscribe on the Mongo cursor observable's updates and iterate through the returned list of docs in Angular, one can use AsyncPipe in an Angular component as follows:

import { MongoObservable, zoneOperator } from 'rxjs';

const Tasks = new MongoObservable.Collection<Task>('tasks');

@Component({
  selector: 'task-list',
  template: `<ul><li *ngFor="let task of tasks | async"></li></ul>`
})
class Tasks {
  tasks = Tasks.find().pipe(zoneOperator());
}

Zone operator

As you can see above we called zoneOperator operator of the cursor observable. This is a special Zone operator that is implemeted by meteor-rxjs for the Angular users' convenience. This operator runs ngZone each time when new data arrives to the Mongo cursor observable, thus we force UI updates at the right time using it.

It makes sense to improve performance of the above Tasks component by debouncing UI updates. In this case we are using Zone operator as well:

class List {
  tasks = Tasks.find()
  .pipe(zoneOperator())
  .pipe(debounce(() => Observable.interval(50)))
  .zone();
}

##License MIT

More Repositories

1

angular-meteor

Angular and Meteor - The perfect stack
Dockerfile
2,362
star
2

graphql-cli

πŸ“Ÿ Command line tool for common GraphQL development workflows
TypeScript
1,983
star
3

graphql-scalars

A library of custom GraphQL Scalars for creating precise type-safe GraphQL schemas.
TypeScript
1,835
star
4

awesome-meteor

A curated, community driven list of awesome Meteor packages, libraries, resources and shiny things
1,419
star
5

graphql-modules

Enterprise Grade Tooling For Your GraphQL Server
TypeScript
1,288
star
6

SOFA

The best way to create REST APIs - Generate RESTful APIs from your GraphQL Server
TypeScript
1,043
star
7

merge-graphql-schemas

A utility library to facilitate merging of modularized GraphQL schemas and resolver objects.
930
star
8

WhatsApp-Clone-Client-React

https://www.tortilla.academy/Urigo/WhatsApp-Clone-Tutorial
TypeScript
610
star
9

WhatsApp-Clone-Tutorial

https://www.tortilla.academy/Urigo/WhatsApp-Clone-Tutorial
530
star
10

WhatsApp-Clone-Server

https://www.tortilla.academy/Urigo/WhatsApp-Clone-Tutorial
TypeScript
453
star
11

angular2-meteor

Angular 2.0 and Meteor - the perfect stack
298
star
12

meteor-ionic

Ionic framework packaged for Meteor.
JavaScript
216
star
13

Ionic-MeteorCLI-WhatsApp

WhatsApp Clone tutorial with Ionic 1.0 and Meteor CLI
JavaScript
206
star
14

meteor-client-bundler

https://blog.meteor.com/leverage-the-power-of-meteor-with-any-client-side-framework-bfb909141008
JavaScript
193
star
15

angular-spinkit

SpinKit (http://tobiasahlin.com/spinkit/) spinners for AngularJS
CSS
189
star
16

meteor-angular2.0-socially

CSS
170
star
17

Ionic2CLI-Meteor-WhatsApp

WhatsApp Clone tutorial with Ionic 2.0 CLI and Meteor Server
TypeScript
163
star
18

meteor-angular-socially

angular-meteor example and tutorial app
TypeScript
155
star
19

angular-meteor-base

TypeScript
131
star
20

WhatsApp-Clone-Client-Angular

TypeScript
73
star
21

Ionic2-MeteorCLI-WhatsApp

WhatsApp Clone tutorial with Ionic 2.0 and Meteor CLI
TypeScript
54
star
22

tortilla

The Framework for tutorials
TypeScript
50
star
23

typescript-node-es-modules-example

Latest Typescript and Node - as bare-bone as possible example app
TypeScript
34
star
24

leumi-leumicard-bank-data-scraper

Open bank data for Leumi bank and Leumi card credit card
JavaScript
28
star
25

apollo-local-state-examples

3 stages and approaches for using GraphQL for your local state
TypeScript
26
star
26

WhatsApp-Clone-GraphQL-Angular-Material

TypeScript
25
star
27

angular-meteor-docs

Source for http://www.angular-meteor.com/
TypeScript
25
star
28

IonicCLI-Meteor-WhatsApp

WhatsApp Clone tutorial with Ionic 1.0 CLI and Meteor Server
JavaScript
22
star
29

angular-embedly

JavaScript
19
star
30

angular2-meteor-accounts-ui

TypeScript
18
star
31

israeli-bank-scrapers-modern-schemas

A new architecture for Poalim bank scraper to hopefully merge into Israeli-bank-scrapers when they are ready
TypeScript
17
star
32

angular-blaze-template

Include Blaze templates in your angular-meteor application
JavaScript
15
star
33

whatsapp-textrepo-angularcli-express

13
star
34

angular-meteor-seed

Seed app for AngularJS and meteor
JavaScript
13
star
35

meteor-static-html-compiler

Compiles static HTML templates so you could import them from a module
TypeScript
10
star
36

angular2-meteor-auto-bootstrap

TypeScript
10
star
37

React-Meteor-Todo-app

JavaScript
10
star
38

Thinkster-MEAN-Tutorial-in-angular-meteor

angular-meteor version of Thinkster.io's mean-stack-tutorial
HTML
10
star
39

meteor-static-templates

Meteor plugin for importing static HTML templates
JavaScript
9
star
40

angular-meteor-auth

JavaScript
7
star
41

accounter-fullstack

TypeScript
7
star
42

tutorial-infrastructure

TypeScript
5
star
43

WhatsApp-Server-GraphQL-Live-RxJS-Meteor

JavaScript
4
star
44

angular-meteor-legacy

Shell
3
star
45

meteor-native-packages

JavaScript
3
star
46

ng-vegas-first-example

HTML
3
star
47

node-express-course

An introduction to Node.js and Express.js servers
1
star
48

tortilla-website

JavaScript
1
star