本文整理汇总了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();