Previously, I utilized a mock that contained an array as the source of data for my entire app by iterating through it. The process worked well.
export const CASES: Case[] = [
{ id: 0,
name: 'Diesel',
portfolioImage: '/assets/images/portfolio/diesel.png',
image: '/assets/images/diesel.jpg',
image2: '/assets/images/diesel/diesel-sunflower.png',
image3: '/assets/images/diesel/diesel-cap.png',
link: '/cases/diesel',
header: 'black'
},
{ id: 1,
name: 'WeWork Berlin',
portfolioImage: '/assets/images/portfolio/berlin.png',
image: '/assets/images/berlin.jpg',
image2: '/assets/images/wework/berlin-logo.png',
image3: '/assets/images/wework/berlin-building.png',
link: '/cases/wework',
header: 'white'
}
];
Now, I am in the process of integrating my app with Firestore. To retrieve data from Firestore, I have implemented the following code within my desired component:
export class PortfolioComponent implements OnInit {
cases;
constructor(private db: AngularFirestore) { }
ngOnInit() {
this.db.collection('entries').valueChanges()
.subscribe(val => this.cases = val);
}
}
The current setup works, but my goal is to make this call only once - specifically, finding a way to fetch the data during app initialization...
- and either merge it with the previous mock dataset,
- or store the data in an array accessible globally
By doing this, my aim is to minimize fetching the data repeatedly and instead retrieve it once, consolidate it, and distribute it accordingly. Similar to how I managed it before integrating Firestore.