Will2Slumped Young Artist Rising Up In The Music Industry

Andrew Williams a young passionate music artist born in Bullhead City, Arizona & raised in a small sanctuary city in the heart of Route 66 called Needles, California. Starting out with a unique place…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Firebase cloud functions

This article is about firebase functions.

A function is a container for code that can be executed when certain conditions are met. Functions in Firebase are used to execute the logic you need when your app interacts with data from other services, like databases or remote servers. This means you can write your app’s business logic synchronously, without having to place it as code in a more complicated language like Java or Swift. You just need to know JavaScript and take a few steps at the beginning of the project to set up Firebase functions correctly on your backend service provider.

The Most Popular Firebase Functions

Below is a list of the most common Firebase functions and their usage:

function() — used to call a function with execute() method.

- used to call a function with execute() method. db function() — used to directly query the database (realtime or asynchronously).

- used to directly query the database (realtime or asynchronously). insertValue() — used to add values from local storage etc. into your data models in real time.

- used to add values from local storage etc. into your data models in real time. values() — used to get the values of the model fields.

- used to get the values of the model fields. logs() — used to get the logs in real time and asynchronously.

- used to get the logs in real time and asynchronously. ref(name) — used to interact with a child along with function execution.

- used to interact with a child along with function execution. onCreate() — called when your creator function is called using trigger().

- called when your creator function is called using trigger(). onUpdate() — similar to onCreate() but called when data changes and firebase re-calls your functions.

- similar to onCreate() but called when data changes and firebase re-calls your functions. user() — returns a reference to the currently authenticated user.

- returns a reference to the currently authenticated user. auth().onAuthStateChanged() — Hooks up a listener which will call the listeners registered with it when the authentication status of Firebase changes for the connected users.

Below is an example of how to use the functions above within your app:

function () {// Get data from db } // Or just get value from local storage function () { db . ref ( ‘data’ ); //Get value } // Get logs function () { logs . once ( ‘info’ , console . log ); } // Call function named “test” function ( ) { //Do something }

Where To Put Your Functions?

Firebase functions are executed inside your app’s JavaScript. You can use any language that runs in a browser, but it is best to have your functions in JavaScript if possible. If you are using Firebase’s hosted version of your data, then the functions only need to be created once and will be available across all the apps that are connected to your Firebase instance. If you are creating or updating a separate app that connects to your Firebase instance, then each app will have to store its own copies of the function code files as part of its local application data storage. you can write functions in Node.js. If you already have a JavaScript server running, you can also serve the Firebase functions there and create your own HTTP server.

Using The Functions In Your App

It is simple to use your Firebase functions in your app:

//Variables in app. js var fbRef;

Conclusion

At the core, Firebase functions allow you to write your app’s business logic synchronously, without having to place it as code in a more complicated language like Java or Swift. You just need to know JavaScript and take a few steps at the beginning of the project to set up Firebase functions correctly on your backend service provider.

Add a comment

Related posts:

Designing for the big screen

In the world of smart phones and laptops, can we really get away with the big screen? Indeed, TVs are now smart. They can connect to the internet of things, play things for you on voice commands…

The Definition of Wealth

What is the true definition of wealth? Some would say it’s the amount of money you have in your bank account, how much you have in stocks, or how many Bitcoins you have. Some people think it’s a…