Skip to content

Commit

Permalink
Merge pull request #49 from fachrihawari/master
Browse files Browse the repository at this point in the history
add firebase remote config service
  • Loading branch information
lupas authored Oct 22, 2019
2 parents 32e514f + 08ebdfb commit f9ba1f1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 20 deletions.
49 changes: 37 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,18 @@ modules: [
}
},
// The following options are optional:
useOnly: ['auth','firestore','functions','storage','realtimeDb', 'messaging', 'performance', 'analytics'],
useOnly: ['auth','firestore','functions','storage','realtimeDb', 'messaging', 'performance', 'analytics', 'remoteConfig'],
customEnv: false,
functionsLocation: 'us-central1',
remoteConfig: {
settings: {
fetchTimeoutMillis: 60000,
minimumFetchIntervalMillis: 43200000,
},
defaultConfig: {
'welcome_message': 'Welcome'
}
}
}
]
],
Expand Down Expand Up @@ -108,21 +117,23 @@ Firebase products supported by nuxt-fire so far:
| Messaging | \$fireMess |
| Performance | \$firePerf |
| Analytics | \$fireAnalytics |
| Remote Config | \$fireConfig |

See [Firebase's official docs](https://firebase.google.com/docs/) for more usage information.

You can further access the objects like so:

| Firebase Obj | Shortcut |
| -------------------- | ------------------ |
| firebase.auth | \$fireAuthObj |
| firebase.database | \$fireDbObj |
| firebase.firestore | \$fireStoreObj |
| firebase.storage | \$fireStorageObj |
| firebase.functions | \$fireFuncObj |
| firebase.messaging | \$fireMessObj |
| firebase.performance | \$firePerfObj |
| firebase.analytics | \$fireAnalyticsObj |
| Firebase Obj | Shortcut |
| ---------------------- | ------------------ |
| firebase.auth | \$fireAuthObj |
| firebase.database | \$fireDbObj |
| firebase.firestore | \$fireStoreObj |
| firebase.storage | \$fireStorageObj |
| firebase.functions | \$fireFuncObj |
| firebase.messaging | \$fireMessObj |
| firebase.performance | \$firePerfObj |
| firebase.analytics | \$fireAnalyticsObj |
| firebase.remoteConfig | \$fireConfigObj |

## Options

Expand All @@ -131,7 +142,7 @@ You can further access the objects like so:
By default, all supported Firebase products are loaded. If you only wish to load certain products (recommended!), add the `useOnly` option.

- type: `Array<string>`
- default: `['auth','firestore','functions','storage','realtimeDb', 'messaging', 'performance', 'analytics']`
- default: `['auth','firestore','functions','storage','realtimeDb', 'messaging', 'performance', 'analytics', 'remoteConfig']`
- required: `false`

#### config[environment]
Expand Down Expand Up @@ -215,6 +226,20 @@ You can change the location with this option.

More information [here](https://firebase.google.com/docs/functions/locations).

#### remoteConfig
You can custom the settings and default config.
```js
{
settings: {
fetchTimeoutMillis: 60000,
minimumFetchIntervalMillis: 43200000,
},
defaultConfig: {
'welcome_message': 'Welcome' // you can add another default config here
}
}
```

## Examples

Check out our [Demo](https://nuxt-fire-demo.firebaseapp.com/) or its [GitHub Repo](https://github.com/lupas/nuxt-fire-demo) for example code.
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ declare module 'vue/types/vue' {
$fireMess: firebase.messaging.Messaging
$fireAnalytics: firebase.analytics.Analytics
$firePerf: firebase.performance.Performance
$fireConfig: firebase.remoteConfig.RemoteConfig
}
}
39 changes: 31 additions & 8 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async (ctx, inject) => {
}

if (options.useOnly.includes('auth')) {
<%= options.useOnly.includes('auth') ? "await import('firebase/auth')" : "" %>
await import('firebase/auth')

const fireAuth = firebase.auth()
const fireAuthObj = firebase.auth
Expand All @@ -19,7 +19,7 @@ export default async (ctx, inject) => {
}

if (options.useOnly.includes('realtimeDb')) {
<%= options.useOnly.includes('realtimeDb') ? "await import('firebase/database')" : "" %>
await import('firebase/database')

const fireDb = firebase.database()
const fireDbObj = firebase.database
Expand All @@ -28,7 +28,7 @@ export default async (ctx, inject) => {
}

if (options.useOnly.includes('firestore')) {
<%= options.useOnly.includes('firestore') ? "await import('firebase/firestore')" : "" %>
await import('firebase/firestore')

const fireStore = firebase.firestore()
const fireStoreObj = firebase.firestore
Expand All @@ -37,7 +37,7 @@ export default async (ctx, inject) => {
}

if (options.useOnly.includes('storage')) {
<%= options.useOnly.includes('storage') ? "await import('firebase/storage')" : "" %>
await import('firebase/storage')

const fireStorage = firebase.storage()
const fireStorageObj = firebase.storage
Expand All @@ -46,7 +46,7 @@ export default async (ctx, inject) => {
}

if (options.useOnly.includes('functions')) {
<%= options.useOnly.includes('functions') ? "await import('firebase/functions')" : "" %>
await import('firebase/functions')

const fireFunc = firebase.app().functions(options.functionsLocation)
const fireFuncObj = firebase.functions
Expand All @@ -56,7 +56,7 @@ export default async (ctx, inject) => {

// Firebase Messaging can only be initiated on client side
if (process.browser && options.useOnly.includes('messaging')) {
<%= options.useOnly.includes('messaging') ? "await import('firebase/messaging')" : "" %>
await import('firebase/messaging')

if (firebase.messaging.isSupported()) {
const fireMess = firebase.messaging()
Expand All @@ -68,7 +68,7 @@ export default async (ctx, inject) => {

// Firebase Performance can only be initiated on client side
if(process.browser && options.useOnly.includes('performance')){
<%= options.useOnly.includes('performance') ? "await import('firebase/performance')" : "" %>
await import('firebase/performance')

const firePerf = firebase.performance()
const firePerfObj = firebase.performance
Expand All @@ -78,11 +78,34 @@ export default async (ctx, inject) => {

// Firebase Analytics can only be initiated on the client side
if(process.browser && options.useOnly.includes('analytics')) {
<%= options.useOnly.includes('analytics') ? "await import('firebase/analytics')" : "" %>
await import('firebase/analytics')

const fireAnalytics = firebase.analytics()
const fireAnalyticsObj = firebase.analytics
inject('fireAnalytics', fireAnalytics)
inject('fireAnalyticsObj', fireAnalyticsObj)
}

// Firebase Remote Config can only be initiated on the client side
if(process.browser && options.useOnly.includes('remoteConfig')) {
await import('firebase/remote-config')

const fireConfig = firebase.remoteConfig()
const fireConfigObj = firebase.remoteConfig

if (options.remoteConfig) {
const { settings: remoteSettings, defaultConfig: remoteDefaultConfig } = options.remoteConfig
if (remoteSettings) {
const { minimumFetchIntervalMillis, fetchTimeoutMillis } = remoteSettings
fireConfig.settings = {
fetchTimeoutMillis: fetchTimeoutMillis ? fetchTimeoutMillis : 60000,
minimumFetchIntervalMillis: minimumFetchIntervalMillis ? minimumFetchIntervalMillis : 43200000
}
}
fireConfig.defaultConfig = (remoteDefaultConfig)
}

inject('fireConfig', fireConfig)
inject('fireConfigObj', fireConfigObj)
}
}

0 comments on commit f9ba1f1

Please sign in to comment.