Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code correction suggestion : chats.components.ts #17

Open
mmazloum opened this issue Jan 26, 2017 · 2 comments
Open

Code correction suggestion : chats.components.ts #17

mmazloum opened this issue Jan 26, 2017 · 2 comments

Comments

@mmazloum
Copy link

mmazloum commented Jan 26, 2017

there is this peace of code in the tutorial (step 3) :
ngOnInit() { this.chats = Chats .find({}) .mergeMap((chats: Chat[]) => Observable.combineLatest( ...chats.map((chat: Chat) => Messages .find({chatId: chat._id}) .startWith(null) .map(messages => { if (messages) chat.lastMessage = messages[0]; return chat; }) ) ) ).zone(); }

I solved some erros in my code adding this minor details :
ngOnInit() { this.chats = Chats .find({}) .mergeMap((chats: Chat[]) => { return Observable.combineLatest( ...chats.map((chat: Chat) => Messages .find({chatId: chat._id}) .startWith(null) .map(messages => { if (messages) chat.lastMessage = messages[0]; return chat; }) ) )} ).zone(); }

infact just add a return on the Observable.combineLatest(...)

@corneezius
Copy link

For some reason, neither of these displays the chat.lastMessage in the view. Anyone else have this problem?

@adrprado
Copy link

adrprado commented Mar 16, 2017

Same problem as @corneezius. Also, can anyone explain this code, please? I know it tries to join both Chats and Messages collections, but... it's().kindOf().tooMuch(nested => isn't.it())?

    this.chats = Chats
      .find({})
      .mergeMap((chats: Chat[]) =>
        Observable.combineLatest(
          ...chats.map((chat: Chat) =>
            Messages
              .find({ chatId: chat._id })
              .startWith(null)
              .map(messages => {
                if (messages) chat.lastMessage = messages[0];
                return chat;
              })
          )
        )
      ).zone();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants