本文整理匯總了TypeScript中firebase/app.firestore函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript firestore函數的具體用法?TypeScript firestore怎麽用?TypeScript firestore使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了firestore函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: atomic
atomic() {
const batch = firebase.firestore().batch();
/// add your operations here
const itemDoc = firebase.firestore().doc('items/myCoolItem');
const userDoc = firebase.firestore().doc('users/userId');
const currentTime = this.timestamp;
batch.update(itemDoc, { timestamp: currentTime });
batch.update(userDoc, { timestamp: currentTime });
/// commit operations
return batch.commit();
}
示例2: beforeEachHelper
export function beforeEachHelper(done): void {
// Create a new Firebase database ref at a random node
firestore = firebase.firestore();
collection = firestore.collection(testCollectionName);
geofirestore = new GeoFirestore(firestore);
geocollection = new GeoCollectionReference(collection);
done();
}
示例3: constructor
constructor() {
const firebaseConfig = {
apiKey: "AIzaSyBw73BRk-qWeZm-fp3-Ijf7s0EemdaWuCQ",
authDomain: "selecquest.firebaseapp.com",
databaseURL: "https://selecquest.firebaseio.com",
projectId: "selecquest",
storageBucket: "selecquest.appspot.com",
messagingSenderId: "434339253679"
};
firebase.initializeApp(firebaseConfig);
this.db = firebase.firestore()
this.db.enablePersistence({experimentalTabSynchronization: true});
}
示例4: setPageView
public setPageView(key): void {
const documentReference = this.afs.collection<ContentDetail>('postDetail').doc(key);
firebase.firestore().runTransaction(page => {
return page.get(documentReference.ref)
.then(doc => {
const newValue = doc.data().view + 1;
page.update(documentReference.ref, {
view: newValue
});
});
}).catch(() => {
console.log('error');
});
}
示例5: salvaLog
//****************************Datas */
salvaLog(type,message,reload=false){
let user = firebase.auth().currentUser;
let d = new Date();
firebase.firestore().collection('logs').add({
type: type,
message : JSON.stringify(message),
date: this.getDate(),
hour: this.getDate('h'),
}).then(ref => {
console.log('Adicionado')
if(reload){
window.location.reload();
}
})
}
示例6: enableProdMode
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
import * as firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
firebase.initializeApp(environment.firebase);
firebase.firestore().settings({ timestampsInSnapshots: true });
platformBrowserDynamic().bootstrapModule(AppModule, { ngZone: 'noop'})
.catch(err => console.error(err));
示例7:
import "firebase/firestore";
import { Project } from "../store/projects/reducer";
const config = {
apiKey: process.env.REACT_APP_API_KEY,
authDomain: process.env.REACT_APP_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_DATABASE_URL,
projectId: process.env.REACT_APP_PROJECT_ID,
storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID
};
app.initializeApp(config);
export const auth: app.auth.Auth = app.auth();
export const firestore: app.firestore.Firestore = app.firestore();
// Required because @firebase/firestore will change
// the behavior for Date objects stored in Firestore.
// Code expecting dates must be updated
// to expect timestamps instead:
// const timestamp = snapshot.get('created_at');
// const date = timestamp.toDate();
const settings = { timestampsInSnapshots: true };
firestore.settings(settings);
// this.auth.onAuthStateChanged(this.onAuthStateChanged);
// onAuthStateChanged = (user: app.User | null) => {
// this.user = user;
// };
示例8:
import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";
firebase.initializeApp({
apiKey: "AIzaSyCjBDyhwbXcp9kEIA2pMHLDGxmCM4Sn6Eg",
authDomain: "canigraduate-43286.firebaseapp.com",
projectId: "canigraduate-43286"
});
export const firestore = firebase.firestore();
firestore.settings({ timestampsInSnapshots: true });
export const auth = firebase.auth();