This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retrieve cities from California | |
db.collection("cities").where("state", "==", "CA") | |
.onSnapshot(function(querySnapshot) { | |
querySnapshot.forEach(function(doc) { | |
// binded to the UI | |
allItems.push(doc.data().name); | |
}); | |
}); | |
// Retrieve cities from Colorado |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- list of California cities goes here --> | |
<ul> | |
... | |
</ul> | |
<!-- list of Colerado cities goes here --> | |
<ul | |
... | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Query for California | |
var californiaRef = citiesRef.where("state", "==", "CA"); | |
// Query for Colorado | |
var coloradoRef = citiesRef.where("state", "==", "CO"); | |
// Create Observables. | |
var california$ = new Rx.Subject(); | |
var colorado$ = new Rx.Subject(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When either California OR Colorado values are emitted from their queries, | |
// combine both observables | |
var californiaOrColorado$ = Rx.Observable.combineLatest(california$, colorado$).switchMap((cities) => { | |
// Destructure the values to combine a single array. | |
var [californiaCities, coloradoCities] = cities; | |
var combined = [ | |
//spread the arrays out to combine as one array | |
...californiaCities, | |
...coloradoCities | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Subscribe to the latest stream that contains both | |
// California and Colorado. | |
californiaOrColorado$.subscribe((result) => { | |
// Output to UI. | |
var citiesEle = document.getElementById('cities'); | |
result.forEach(city => { | |
var itemEle = document.createElement("li"); | |
itemEle.textContent = city.name; | |
citiesEle.appendChild(itemEle); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
caOrCoCities$: Observable<City[]>; | |
... | |
const californiaRef = this.angularFirestore | |
.collection("cities", ref => ref.where("state","==","CA")); | |
const coloradoRef = this.angularFirestore | |
.collection("cities", ref => ref.where("state","==","CO")); | |
this.caOrCoCities$ = Observable | |
.combineLatest(californiaRef.valueChanges(), | |
coloradoRef.valueChanges()) | |
.switchMap(cities => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li *ngFor="let cities of caOrCoCities$ | async as caOrCoCities"> | |
... | |
</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { collection } from 'rxfire/firestore'; | |
import { map } from 'rxjs/operators'; | |
// Query for California | |
var californiaRef = citiesRef.where("state", "==", "CA"); | |
// Query for Colorado | |
var coloradoRef = citiesRef.where("state", "==", "CO"); | |
// Create Observables ready for subscribe(). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { combineLatest } from 'rxjs'; | |
var californiaOrColorado$ = combineLatest(california$, colorado$) | |
.pipe( | |
map((cities) => { | |
// Destructure the values to combine a single array. | |
var [californiaCities, coloradoCities] = cities; | |
return [ | |
//spread the arrays out to combine as one array | |
...californiaCities, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as functions from "firebase-functions"; | |
import * as admin from "firebase-admin"; | |
const firebase = admin.initializeApp(); | |
export const deletePhotos = functions.firestore | |
.document("posts/{postId}") | |
.onDelete((snap, context) => { | |
const { postId } = context.params; | |
const bucket = firebase.storage().bucket(); |
OlderNewer