Skip to content

Commit

Permalink
Merge branch 'liveSubscriptions' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ijager committed Jan 21, 2017
2 parents ad59ccd + 8ddd5f1 commit c40f14e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/MeteorObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import {Observable, Subscriber} from 'rxjs';
import {isMeteorCallbacks, forkZone, removeObserver} from './utils';

let liveSubscriptions = [];

function throwInvalidCallback(method: string) {
throw new Error(
`Invalid ${method} arguments:
Expand Down Expand Up @@ -161,10 +163,28 @@ export class MeteorObservable {
// Execute subscribe lazily.
if (subHandler === null) {
subHandler = subscribe();
if (liveSubscriptions.find(sub => sub === subHandler.subscriptionId)) {
// subscription already exists, call observer.next() since Meteor won't.
observer.next();
} else {
liveSubscriptions.push(subHandler.subscriptionId);
}
}
return () => {
removeObserver(observers,
observer, () => subHandler.stop());
observer, () => {
// remove subscription from liveSubscriptions list
let i = liveSubscriptions.findIndex(
sub => sub === subHandler.subscriptionId
);

if (i > -1) {
liveSubscriptions.splice(i, 1);
}

subHandler.stop();

});
};
});
}
Expand Down

0 comments on commit c40f14e

Please sign in to comment.