What is the best way to combine the emissions of flatMap?

Following the switchMap operator, we utilized the flatMap operator to access the object observable data

return this.db.list(`UserPlaces/${this.authData.auth.auth.currentUser.uid}`, {
    query: {
      orderByChild: 'deleted',
      equalTo: false
    }
  })
  .map((locations: any) => {
    console.log(JSON.stringify(locations,null,2)); // this log is called 0
    return locations.map(location => {
      return location.$key;
    });
  }).switchMap(ids => {
    return ids.map(id => {
      console.log(id) // this log is called 1
      return this.db.object(`Devices/${id}`)
    });
  }).flatMap((x: any) => {
    console.log(x); // this log is called 2
    return x;
  }).map((x:any)=>{
    console.log(x); 
     if(!x.deleted){
      return x;
    }
  })
  .do(console.log) // and this log is called 3

Log 0:

[
  {
    "deleted": false,
    "guest": false,
    "owner": true
  },
  {
    "deleted": false,
    "guest": false,
    "owner": true
  },
  {
    "deleted": false,
    "guest": false,
    "owner": true
  },
  {
    "deleted": false,
    "guest": false,
    "owner": true
  },
  {
    "deleted": false,
    "guest": false,
    "owner": true
  },
  {
    "deleted": false,
    "guest": false,
    "owner": true
  },
  {
    "deleted": false,
    "guest": false,
    "owner": true
  }
] 

log 1:

-L8CmrV8BBQCVv_0x_-6
-L8CnDqHz_VWP9dpw-tz
-L8CxQ_bz4EQSPa4STUd
-L8CxSaF1JdHwhn3YyrC
-L8WVlwWj-ghpZsx2PEE
-L8WW5QbxxNMeWonNdSg
-L8XJHI0-ZhPAA9Xy3Sx

log 2:

FirebaseObjectObservable {_isScalar: false, $ref: U, source: FirebaseObjectObservable, operator: ObserveOnOperator}
FirebaseObjectObservable {_isScalar: false, $ref: U, source: FirebaseObjectObservable, operator: ObserveOnOperator}
FirebaseObjectObservable {_isScalar: false, $ref: U, source: FirebaseObjectObservable, operator: ObserveOnOperator}
FirebaseObjectObservable {_isScalar: false, $ref: U, source: FirebaseObjectObservable, operator: ObserveOnOperator}
FirebaseObjectObservable {_isScalar: false, $ref: U, source: FirebaseObjectObservable, operator: ObserveOnOperator}
FirebaseObjectObservable {_isScalar: false, $ref: U, source: FirebaseObjectObservable, operator: ObserveOnOperator}
FirebaseObjectObservable {_isScalar: false, $ref: U, source: FirebaseObjectObservable, operator: ObserveOnOperator}

log 3:

{deleted: false, id: "", name: "new place", owner: "cS81XkHhVHNv0nmpVit0Glpuc1t1", tone: "default", …} {deleted: false, id: "", name: "new one", owner: "cS81XkHhVHNv0nmpVit0Glpuc1t1", tone: "default", …} {deleted: false, id: "", name: "nice", owner: "cS81XkHhVHNv0nmpVit0Glpuc1t1", tone: "default", …} {deleted: false, id: "", name: "new one", owner: "cS81XkHhVHNv0nmpVit0Glpuc1t1", rooms: {...}, …} {deleted: false, id: "", name: "das", owner: "cS81XkHhVHNv0nmpVit0Glpuc1t1", tone: "default", …}

I aim to combine the separate objects from log 3 into an array of objects for display.

This will facilitate presenting an ion-select that iterates through the array to showcase the place names.

Thank you.

Answer №1

When the source is executed:

return this.db.list(`UserPlaces/${this.authData.auth.auth.currentUser.uid}`, { ... })
  ...
  .toArray()
  .do(console.log) // and this message appears 3 times

or if it does not gather results using scan():

return this.db.list(`UserPlaces/${this.authData.auth.auth.currentUser.uid}`, { ... })
  ...
  .scan((acc, item) => [...acc, item], [])
  .do(console.log) // and this message appears 3 times

By the way, it seems like you're intentionally processing the array anyway with:

...
.flatMap((x: any) => {
  console.log(x); // this message appears twice
  return x;
}
...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Customizing the like button functionality for individual elements, with the ability to unlike, utilizing Angular

I am looking to implement a Like button feature that increments the counter when clicked once, and decrements it on another click. I have multiple elements with the like button and I want them to function independently from each other. Please note that ...

Angular 5 and Bootstrap card with enhanced double-click functionality

I want to design a Bootstrap card that can trigger two of my custom methods. <div (click)="TEST1()" class="card" style="width: 18rem;"> <div class="card-body"> <h5 class="card-title">Card title</h5> <button (click)="(T ...

Is there a way to have my accordion adjust automatically?

I have developed a dynamic accordion component that populates its values from the parent component. However, I am facing an issue where each accordion does not respond individually to clicks. Whenever I click on any accordion, only the first one expands an ...

Tips for incorporating the "build" directory into the Travis-CI build process and deployment of an npm module

Currently, I am working with a Typescript module that has a directory ./src And I also have travis-ci set up for the project. language: node_js node_js: - 5.1.0 install: - npm install - npm install -g mocha - npm install -g gulp - npm install -g tsd - ...

Accessing and parsing a JSON file within a customized Angular library

Currently, I am facing an issue while trying to develop a custom library in Angular 8. My goal is to extract data from a JSON file within the Angular library's working file. However, upon building the library and integrating it into my project, I enco ...

Encountering errors in Typescript build due to issues in the node_modules directory

While running a typescript build, I encountered errors in the node_modules folder. Despite having it listed in the exclude section of my tsconfig.json file, the errors persist. What's puzzling is that another project with identical gulpfile.js, tsconf ...

Vue3 and Typescript issue: The property '$el' is not recognized on type 'void'. What is the correct way to access every existing tag type in the DOM?

Currently, I am in the process of migrating a Vue2 project to Vue3 and Typescript. While encountering several unusual errors, one particular issue with $el has me puzzled. I have been attempting to target every <g> tag within the provided template, ...

Is there a way to achieve a seamless compilation in TypeScript?

Hopefully this is straightforward! TypeScript Latest version: 1.9.0-dev.20160512 (can be installed using npm install -g typescript@next as suggested by @basarat) Node v5.11.0 Windows 10.0.10586 First file: u1c.ts import * as u1u from "./u1u.ts" let p = ...

A method for transferring information stored in chrome.storage to a variable within an Angular component

How can I effectively assign data fetched from chrome.storage.sync.get to my Angular component's variable? Below is the code snippet of my component: export class KTableComponent implements OnInit { words: string[] = []; constructor() { } ...

Create a dynamic function that adds a new property to every object in an array, generating unique values for

On my server, I have a paymentList JSON that includes date and time. Utilizing moment.js, I am attempting to create a new property called paymentTime to store the time data, but it seems to not update as expected. this.paymentList.forEach(element => ...

Error TS2339: The specified property is not found within the given type of 'IntrinsicAttributes & IntrinsicClassAttributes<FormInstance<{}, Partial<ConfigProps<{}, {}>>>> & ...'

Recently diving into the world of TypeScript and Redux, I've been tackling the SimpleForm example from redux-form. Below is the form component I'm working with: import * as React from 'react'; import {Field, reduxForm} from 'redu ...

Unusual TypeScript Syntax

While examining a TypeScript function designed to calculate average run time, I stumbled upon some unfamiliar syntax: func averageRuntimeInSeconds(runs []Run) float64 { var totalTime int var failedRuns int for _, run := range runs { ...

Attempting to design the appearance of the form fields within a Mat-Card

As someone new to UI development and lacking in-depth knowledge of css, I have been searching for examples to style a login page using Angular Material. My main struggle right now is getting the form fields to expand the width of the card (minus the paddin ...

There is no index signature that includes a parameter of type 'number' on the specified type xx

Here are the data types I am currently utilizing: export interface IHelpDeskTextData { supportPaneltext: ContactHelpdeskContex[]; selected?: number | null; brandOptions?: string[]; textPanel?: ITextPanel[]; } export class ContactHelpdeskContex { ...

Angular Fails to Identify Chart.js Plugin as an Options Attribute

Encountering issues with using the 'dragData' plugin in Chart.js 2.9.3 within an Angular environment: https://github.com/chrispahm/chartjs-plugin-dragdata After importing the plugin: chartjs-plugin-dragdata, I added dragdata to the options as sh ...

Rotating images on a canvas

We're currently implementing Ionic and Angular in our project. One issue we are facing is regarding image rotation on canvas. When we click on an image, the rotation works perfectly if it's a jpg file. However, when we pass a base64 image, the r ...

Can NgZone be utilized within a shared service instance?

I am currently working on creating an injectable singleton service for my application that will provide all components with information about the window width and height, as well as notify them when the page is scrolled or resized. Below is the code snipp ...

Oops! There was an unexpected error: TypeError - It seems that the property 'title' cannot be read because it is undefined

HTML document example <ion-header> <ion-toolbar color="danger"> <ion-buttons> <button ion-button navPop icon-only> <ion-icon ios="ios-arrow-back" md="md-arrow-back"></ion-icon> </button> ...

Discover the magic of Angular8 by learning how to effortlessly display and conceal headers and data within the body of a table

I have implemented table binding dynamically from a TS file. When the detail view button is clicked, the data is shown or hidden based on true and false conditions. However, I need a label to be displayed under one of two specific conditions. Is there a mo ...

What is the best way to convert a JSON string received from Angular into a Java Object within a Spring

I am currently utilizing WebSocket to create a chat application. Below is the code from my Angular application that sends a MessageModel object to the backend after converting it into a JSON string: sendMessage(message: MessageModel){ let data = JSON.str ...