Firebase 与 AngularFire [英] Firebase vs AngularFire

查看:52
本文介绍了Firebase 与 AngularFire的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Angular App,它与 Firebase 实时数据库相连.我目前正在使用 AngularFire 来访问 Firebase 数据库.

I am working on an Angular App, which is connected with Firebase Real-time database. I am currently using AngularFire for accessing Firebase database.

在阅读了 Vanilla FirebaseAngularFire 文档后,并在实现了我的应用程序的某些部分后,我看到了 Firebase 所需的所有东西数据库可以在 Vanilla Firebase 的帮助下实现,无需 AngularFire 的任何帮助.

After reading Vanilla Firebase and AngularFire documentation, and after implementing some portion of my app, I saw that all the things required from Firebase database can be achieved with the help of Vanilla Firebase, without any help of AngularFire.

此外,与 Vanilla Firebase 相比,AngularFire 仅提供有限数量的资源.那么,为什么我要使用 AngularFire 而不是 Vanilla Firebase,因为它有很多可用的资源?我无法理解这种情况.

Also, AngularFire provides only limited number of resources as compared to Vanilla Firebase. So, why would I want to use AngularFire, instead of Vanilla Firebase, when it has many resources available with it? I cant get my head around this scenario.

使用 AngularFire 比使用 Vanilla Firebase 有什么好处?

What are the benefits of using AngularFire over Vanilla Firebase?

推荐答案

Angularfire

嗯,angularfire 是一个辅助库.它应该通过提供为使 angular 和 firebase 之间的集成更加无缝而创建的绑定来让您的生活更轻松.

Angularfire

Well, angularfire is sort of a helper library. It's supposed to make your life easier by providing bindings that were created in order to make the integration between angular and firebase more seamless.

一个实际例子:

开发人员通常需要使用数组来显示数据.但是,firebase 不会以数组形式存储任何数据.相反,它使用类似 JSON 的结构.话虽如此,为了让每个人都能更轻松地从 firebase 中检索数据作为数组,angularfire 为您提供了 $firebaseArray(),它本质上是从某个位置转换数据并在数组中返回相同的数据(只读伪数组).

Developers normally need to make use of arrays in order to display data. However, firebase does not store any data in array form. Instead, it uses a JSON-like structure. That being said, to make it easier for everyone to wrap their heads around retrieving data from firebase as an array, angularfire gives you $firebaseArray(), which essentially converts the data from a certain location and returns you that same data inside of an array (a read-only pseudo-array).

请注意,所有这些都可以通过使用 vanilla firebase 手动检索数据,然后将您从 firebase 获得的数据(作为对象)转换为客户端的数组来完成.

Note that all of that could be accomplished by just retrieving the data manually with vanilla firebase and then converting the data you got from firebase (as an object) to an array on the client side.

当 angularfire 对您有意义并且让您的生活更轻松时,您应该使用它.这就是它的用途.如果您可以通过使用 vanilla firebase 来完成您需要的一切,那么没有理由使事情复杂化.我还应该指出,您可以同时使用 firebase 和 angularfire.正如评论中提到的 carant,这不是一个非此即彼的选择,因为两者都可以很好地配合使用.这意味着您可以将 vanilla firebase 用于更具体的用例,同时将 angularfire 用于其他目的.

You should use angularfire when it makes sense to you and if it makes your life easier. That is what it is there for. If you can accomplish everything you need by just using vanilla firebase, there's no reason to complicate things. I should also point out that you can use firebase and angularfire at the same time. As cartant mentioned in the comments, it is not an either-or choice, as both play together very well. That means that you can use vanilla firebase for more specific use cases, while utilizing angularfire for other purposes.

总而言之,使用 angularfire 可以做的一切也可以通过 vanilla firebase 实现,尽管它可能需要一大堆额外的代码.换句话说,angularfire 建立在 firebase 之上,不会为您提供新的 firebase 功能.从本质上讲,它使使用 angular 的 firebase 变得更加有趣和实用.

All in all, everything that is possible to do with angularfire is also possible with vanilla firebase, although it may require a whole bunch of extra code. In other words, angularfire is built on top of firebase and will not offer you new firebase features. Essentially, it makes using firebase with angular a lot more fun and practical.

Angularfire2 是一个完全不同的故事,因为它实际上将 RxJS observables 和其他反应式模式与 firebase 集成在一起,所有这些在 vanilla firebase 中默认不可用.

Angularfire2 is a totally different story, since it actually integrates RxJS observables and other reactive patterns with firebase, all of which are not available by default in vanilla firebase.

但在大多数情况下,它们都用于相同的目的.Angularfire2 也是 firebase 之上的抽象,它提供实时绑定,旨在促进 firebase 和 angular2 之间的集成.此外,它还让您可以以一种被动的方式使用 firebase.

For the most part though, they both serve the same purpose. Angularfire2 is also an abstraction on top of firebase that provides real time bindings which were meant to facilitate the integration between firebase and angular2. Additionally, it gives you the possibility of working with firebase in a reactive way.

这篇关于Firebase 与 AngularFire的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆