Skip to content

Commit

Permalink
Step 10.11: Subscribe to the party publication
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored and dotansimha committed Nov 27, 2016
1 parent f2aa5d1 commit df59e89
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions client/imports/app/parties/party-details.component.ts
@@ -1,7 +1,8 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
import { Meteor } from 'meteor/meteor';
import { Meteor } from 'meteor/meteor';
import { MeteorObservable } from 'meteor-rxjs';

import 'rxjs/add/operator/map';

Expand All @@ -18,6 +19,7 @@ export class PartyDetailsComponent implements OnInit, OnDestroy {
partyId: string;
paramsSub: Subscription;
party: Party;
partySub: Subscription;

constructor(
private route: ActivatedRoute
Expand All @@ -27,9 +29,15 @@ export class PartyDetailsComponent implements OnInit, OnDestroy {
this.paramsSub = this.route.params
.map(params => params['partyId'])
.subscribe(partyId => {
this.partyId = partyId
this.partyId = partyId;

this.party = Parties.findOne(this.partyId);
if (this.partySub) {
this.partySub.unsubscribe();
}

this.partySub = MeteorObservable.subscribe('party', this.partyId).subscribe(() => {
this.party = Parties.findOne(this.partyId);
});
});
}

Expand All @@ -50,5 +58,6 @@ export class PartyDetailsComponent implements OnInit, OnDestroy {

ngOnDestroy() {
this.paramsSub.unsubscribe();
this.partySub.unsubscribe();
}
}

0 comments on commit df59e89

Please sign in to comment.