mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
angular-demo: rewrite rx wrapper
Use latest API and ensure unsubscription will be done.
This commit is contained in:
parent
a2148b36b3
commit
ea5d6db9b2
@ -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",
|
||||
|
@ -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) { }
|
||||
|
9
examples/angular/src/app/gun.helper.ts
Normal file
9
examples/angular/src/app/gun.helper.ts
Normal 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()
|
||||
);
|
||||
}
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user