typescriptmeteorrxjsobservableangular-meteor

Meteor Angular forkjoin for server side data initialization


I'm trying to use the RxJS Observable.forkjoin method to synchronize my serverside created fake data but it never triggers the subscription if I try to use them with MeteorObservable.Collection<any>.insert methods.

If I try to use the same with "original" angular Observable like observableBatchTest.push(Observable.from([i])); there is no problem and the subscription is triggered fine.

Here's a small minimal example of the existing problem:

function initFakeChats(numberOfChats: number): Observable<{}[]> {

 let observableBatch = [];

  for (var i = 0; i < numberOfChats; i++) {
    var data = {
      messages: Fake.word(),
      name: Fake.word(),
    };
    observableBatch.push(Chats.insert(data));
  }
  return Observable.forkJoin(observableBatch);
}

export function fakeAll() {

  let chatIds = initFakeChats(2).subscribe(
    fakeChatIds => {
      console.dir('Finished Fake Chats');
      console.dir(fakeChatIds);
      return fakeChatIds;
    },
    error => {
      console.dir(error);
    });
}

Is there a special meteor way to reach something similar like that? For example dynamic nested Meteor.call?


Solution

  • I know the problem now - related to this topic https://github.com/Urigo/meteor-rxjs/issues/25 .

    The MeteorObservable subscriptions never fire a complete event - because of that there is no possibility to fire a forkjoin (which needs all inner observables fired completed).

    combineLatest works instead - I just have now to workout to get the recognition of something like "completed" (could use the array size of a fake object loop to check if the subscription callbacks are "completed"), before run next fake creation tasks.