angular-demo: rewrite rx wrapper

Use latest API and ensure unsubscription will be done.
This commit is contained in:
Victor Noël 2017-04-19 21:13:17 +02:00
parent a2148b36b3
commit ea5d6db9b2
4 changed files with 15 additions and 5 deletions

View File

@ -23,7 +23,6 @@
"core-js": "^2.4.1",
"express-http-proxy": "^0.11.0",
"gun": "^0.7.2",
"gun-edge": "^0.8.8",
"ngx-pipes": "^1.5.10",
"rxjs": "^5.3.0",
"underscore": "^1.8.3",

View File

@ -1,11 +1,10 @@
import { Component, OnInit } from '@angular/core';
import { $rx } from 'gun-edge/edge/observable/rx';
import Gun from 'gun/gun';
import { Observable } from 'rxjs/Observable';
import { GunDb } from 'app/gun.service';
import { omit } from 'underscore';
import { Subject } from 'rxjs/Subject';
import { GunDb } from 'app/gun.service';
import { rx$ } from 'app/gun.helper';
@Component({
selector: 'app-root',
@ -16,7 +15,7 @@ export class AppComponent implements OnInit {
newTodo = '';
todos = this.db.gun.get('todos');
todos$: Observable<string[]> = $rx(this.todos)
todos$: Observable<string[]> = rx$(this.todos)
.map(o => omit(o, '_'));
constructor(private db: GunDb) { }

View File

@ -0,0 +1,9 @@
import { Observable } from 'rxjs/Observable';
export function rx$(node): Observable<any> {
return Observable.fromEventPattern(
// needed to clone the object because of #355
h => node.on(v => h({ ...v })),
(_, s) => s.off()
);
}

View File

@ -5,6 +5,9 @@ import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/fromEventPattern';
if (environment.production) {
enableProdMode();