Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@paulbarre/vue-firebase

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@paulbarre/vue-firebase - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

4

Changelog.md
# Changelog
## 0.4.0
* Provide `getFromCache`, a custom method to `$firestore` equivalent to `docRef.get({ source: 'cache' })` but download data from server if no data in cache found
## 0.3.0

@@ -4,0 +8,0 @@

@@ -195,2 +195,21 @@ module.exports =

enablePersistence () {
app_default.a.firestore().enablePersistence()
app_default.a.firestore().getFromCache = async function (ref, { source = 'cache'} = {}) {
try {
return await ref.get({ source })
} catch (error) {
if (source === 'cache') {
return await this.getFromCache(ref, {
source: 'default'
})
} else {
throw error
}
}
}
},
setupFirestore (Vue, { config = {}, firestore = {} }) {

@@ -203,3 +222,3 @@ if (!config || !config.projectId) {

if (firestore.enablePersistence) {
app_default.a.firestore().enablePersistence()
this.enablePersistence()
}

@@ -206,0 +225,0 @@ Vue.prototype.$firestore = app_default.a.firestore()

2

package.json

@@ -5,3 +5,3 @@ {

"description": "Vue plugin to easily setup Firebase API",
"version": "0.3.0",
"version": "0.4.0",
"license": "GPL-3.0-or-later",

@@ -8,0 +8,0 @@ "main": "dist/VueFirebasePlugin.common.js",

@@ -8,3 +8,3 @@ # Firebase plugin for Vue.js

- [x] Connection to Firestore
- [x] Configure offline persistence
- [x] Configure offline persistence, providing useful function to get document from cache
- [x] Authentication feature

@@ -119,2 +119,26 @@

`getFromCache`
Enabling the offline cache to Firestore will provide a custom method to `$firestore` in order to get a document from cache or from server if not found into cache.
Using default firebase API, to get a document from cache:
```js
const myCollectionRef = this.$firestore.collection('myCollection')
const snapshot = await myCollectionRef.doc('myDoc').get({ source: 'cache' })
```
If no data for the document `myDoc` is found into the cache, an error is thrown.
To provide automatically a fallback to the server, it is possible to do the following:
```js
const myCollectionRef = this.$firestore.collection('myCollection')
const snapshot = await this.$firestore.getFromCache(doc('myDoc'))
```
If no data is found into the cache, the data from the server will be downloaded. If no data is found on the server, `undefined` will be returned.
> Attention, to be able to use **getFromCache**, **enablePersistence** has to be set to true.
For more information on how to use `$firestore`, check at the [official documentation](https://firebase.google.com/docs/reference/node/firebase.firestore).

@@ -121,0 +145,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc