Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add firebase remote config service #49

Merged
merged 4 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ 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',
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here add

remoteConfig: {
   minimumFetchIntervalMillis: 3600000,
   defaultConfig: {
      'welcome_message': 'Welcome'
   }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And later we would also need to add a description to line 206

Expand Down Expand Up @@ -103,21 +103,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 @@ -126,7 +128,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
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
}
}
26 changes: 18 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,21 @@ 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
inject('fireConfig', fireConfig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about we add the following functionality here?

const optionalFetchInterval = options.remoteConfig.minimumFetchIntervalMillis
remoteConfig.settings = {
  minimumFetchIntervalMillis: optionalFetchInterval ? optionalFetchInterval : 3600000,
};

remoteConfig.defaultConfig = (options.remoteConfig.defaultConfig)

So remoteConfig is setup completely and the default values can, if needed, be passed through nuxt.config.js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was just a quick write up, need to do it better since this will break if options.remoteConfig doesn't exist.

inject('fireConfigObj', fireConfigObj)
}
}