{"id":13481787,"url":"https://github.com/Urigo/meteor-rxjs","last_synced_at":"2025-03-27T12:31:25.130Z","repository":{"id":57140695,"uuid":"67453259","full_name":"Urigo/meteor-rxjs","owner":"Urigo","description":"Exposing Mongo Cursor as RxJS Observable","archived":false,"fork":false,"pushed_at":"2019-11-18T11:44:13.000Z","size":325,"stargazers_count":120,"open_issues_count":63,"forks_count":37,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-05-22T04:32:13.232Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Urigo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-05T21:56:01.000Z","updated_at":"2023-05-11T13:12:38.000Z","dependencies_parsed_at":"2022-09-05T01:30:35.967Z","dependency_job_id":null,"html_url":"https://github.com/Urigo/meteor-rxjs","commit_stats":null,"previous_names":["urigo/mongo-rxjs-observable"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Urigo%2Fmeteor-rxjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Urigo%2Fmeteor-rxjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Urigo%2Fmeteor-rxjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Urigo%2Fmeteor-rxjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Urigo","download_url":"https://codeload.github.com/Urigo/meteor-rxjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245844942,"owners_count":20681805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:00:55.673Z","updated_at":"2025-03-27T12:31:25.094Z","avatar_url":"https://github.com/Urigo.png","language":"TypeScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Meteor + RxJS\r\n\r\n[![npm version](https://badge.fury.io/js/meteor-rxjs.svg)](https://badge.fury.io/js/meteor-rxjs) [![Build Status](https://travis-ci.org/Urigo/meteor-rxjs.svg?branch=master)](https://travis-ci.org/Urigo/meteor-rxjs) [![bitHound Overall Score](https://www.bithound.io/github/Urigo/meteor-rxjs/badges/score.svg)](https://www.bithound.io/github/Urigo/meteor-rxjs) [![bitHound Code](https://www.bithound.io/github/Urigo/meteor-rxjs/badges/code.svg)](https://www.bithound.io/github/Urigo/meteor-rxjs) [![bitHound Dev Dependencies](https://www.bithound.io/github/Urigo/meteor-rxjs/badges/devDependencies.svg)](https://www.bithound.io/github/Urigo/meteor-rxjs/master/dependencies/npm) \r\n\r\nHarness Meteor reactivity with RxJS.\r\n\r\nRxJS 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.\r\n\r\n# API Documentation\r\n\r\nAPI documentation is available inside this repository, [here](https://github.com/Urigo/meteor-rxjs/tree/master/docs).\r\n\r\n## Mongo Cursor Observable\r\nAs soon as you install this package (`npm install meteor-rxjs`), you have ability to use a special Mongo collection class that works\r\nwith cursor observables instead of the ordinary Mongo cursors. In other words, one can subscribe on the Mongo cursor's data updates now as follows:\r\n\r\n```ts\r\n\r\nimport {MongoObservable} from 'meteor-rxjs';\r\n\r\nconst Tasks = new MongoObservable.Collection\u003cTask\u003e('tasks');\r\n\r\nTasks.find({checked: false})\r\n  .map(tasks =\u003e tasks.length)\r\n  .subscribe(todoCount =\u003e console.log(todoCount));\r\n\r\n```\r\n\r\nSince 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:\r\n\r\n```ts\r\n\r\nimport {Observable} from 'rxjs';\r\n\r\nimport {debounce, map} from 'rxjs/operators';\r\n\r\nTasks.find({checked: false})\r\n  .pipe(debounce(() =\u003e Observable.interval(50)))\r\n  .pipe(map(tasks =\u003e tasks.length))\r\n  .subscribe(todoCount =\u003e console.log(todoCount));\r\n\r\n```\r\n\r\n## Usage with Meteor packages\r\n\r\nMeteor 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:\r\n```ts\r\nlet collection = new Mongo.Collection('foo');\r\nlet observable = new MongoObservable.Collection(collection);\r\ncollection.attachSchema(...); // with SimpleSchema package\r\n```\r\n\r\n## Usage in Angular\r\n\r\nAngular has tight integration with RxJS since Angular is desinged to support reactive UI updates.\r\nOne of the realizations of this integration is `AsyncPipe`, which is supposed to be used with RxJS observables.\r\n\r\nIn 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:\r\n\r\n```ts\r\nimport { MongoObservable, zoneOperator } from 'rxjs';\r\n\r\nconst Tasks = new MongoObservable.Collection\u003cTask\u003e('tasks');\r\n\r\n@Component({\r\n  selector: 'task-list',\r\n  template: `\u003cul\u003e\u003cli *ngFor=\"let task of tasks | async\"\u003e\u003c/li\u003e\u003c/ul\u003e`\r\n})\r\nclass Tasks {\r\n  tasks = Tasks.find().pipe(zoneOperator());\r\n}\r\n\r\n````\r\n\r\n### Zone operator\r\n\r\nAs you can see above we called `zoneOperator` operator of the cursor observable. This is a special\r\nZone operator that is implemeted by `meteor-rxjs` for the Angular users' convenience.\r\nThis operator runs ngZone each time when new data arrives to the Mongo cursor observable,\r\nthus we force UI updates at the right time using it.\r\n\r\nIt makes sense to improve performance of the above `Tasks` component by debouncing UI updates.\r\nIn this case we are using Zone operator as well:\r\n\r\n```ts\r\n\r\nclass List {\r\n  tasks = Tasks.find()\r\n  .pipe(zoneOperator())\r\n  .pipe(debounce(() =\u003e Observable.interval(50)))\r\n  .zone();\r\n}\r\n\r\n```\r\n\r\n##License\r\nMIT\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUrigo%2Fmeteor-rxjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FUrigo%2Fmeteor-rxjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUrigo%2Fmeteor-rxjs/lists"}