mirror of
https://github.com/amark/gun.git
synced 2026-03-08 01:51:43 +00:00
angular-demo: rewrite rx wrapper
Use latest API and ensure unsubscription will be done.
This commit is contained in:
@@ -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()
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user