- Serverless Web Applications with React and Firebase
- Harmeet Singh Mayur Tanna
- 244字
- 2021-08-27 19:11:12
How does it work?
Once you write and deploy a function, Google's servers start listening to those functions immediately, that is listening for events and running the function when it gets triggered. As the load of your app increases or decreases, it responds by rapidly scaling the number of virtual server instances needed to run your function faster. If the function is deleted, idle, or updated by you, then instances are cleaned up and replaced by new instances. In the case of deletion, it also removes the connection between functions and the event provider.
Given here are the events that are supported by Cloud Functions:
- onWrite(): It triggers when data is created, destroyed, or changed in the Realtime Database
- onCreate(): It triggers when new data is created in the Realtime Database
- onUpdate(): It triggers when data is updated in the Realtime Database
- onDelete(): It triggers when data is deleted from the Realtime Database
Here's a code sample of the cloud function makeUppercase:
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
const original = event.data.val();
console.log('Uppercasing', event.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return event.data.ref.parent.child('uppercase').set(uppercase);
});
After you write the cloud function, we can also test and monitor our functions.
推薦閱讀
- 多媒體CAI課件設(shè)計(jì)與制作導(dǎo)論(第二版)
- Mobile Web Performance Optimization
- Mastering Objectoriented Python
- AngularJS Web Application Development Blueprints
- R語(yǔ)言數(shù)據(jù)可視化之美:專業(yè)圖表繪制指南
- Full-Stack Vue.js 2 and Laravel 5
- The HTML and CSS Workshop
- Mastering Python Design Patterns
- Arduino計(jì)算機(jī)視覺編程
- UML2面向?qū)ο蠓治雠c設(shè)計(jì)(第2版)
- Node.js從入門到精通
- Bitcoin Essentials
- HTML5+CSS3+jQuery Mobile+Bootstrap開發(fā)APP從入門到精通(視頻教學(xué)版)
- 多接入邊緣計(jì)算實(shí)戰(zhàn)
- Switching to Angular 2