Skip to content

Commit

Permalink
feat(onesignal): move init options under init
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Nov 17, 2017
1 parent f3b5b3e commit dd61c18
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ modules: [

// Options
oneSignal: {
appId: 'YOUR_APP_ID',
// ...your other init settings (see references below)
init: {
appId: 'YOUR_APP_ID',
}
}
```

Expand Down
23 changes: 7 additions & 16 deletions packages/onesignal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@ function addOneSignal (moduleOptions) {

// Merge options
const defaults = {
// Special options
OneSignalSDK: undefined,
cdn: false,
GcmSenderId: '482941778795',
importScripts: [
'/sw.js'
],
// SDK init options
// https://documentation.onesignal.com/docs/web-push-sdk#section--init-
allowLocalhostAsSecureOrigin: true,
welcomeNotification: {
disable: true
init: {
allowLocalhostAsSecureOrigin: true,
welcomeNotification: {
disable: true
}
}
}

Expand Down Expand Up @@ -117,20 +116,12 @@ function addOneSignal (moduleOptions) {
makeSW('OneSignalSDKWorker.js', [].concat(options.importScripts || []).concat(options.OneSignalSDK))
makeSW('OneSignalSDKUpdaterWorker.js', [options.OneSignalSDK])

// Add OneSignal init plugin
const onsOpts = Object.assign({}, options)
delete onsOpts.OneSignalSDK
delete onsOpts.cdn
delete onsOpts.GcmSenderId
delete onsOpts.importScripts

// Add OneSignal plugin
this.addPlugin({
src: path.resolve(__dirname, 'templates/plugin.js'),
ssr: false,
fileName: 'onesignal.js',
options: {
onsOpts
}
options
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/onesignal/templates/plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.$OneSignal = window.OneSignal = window.OneSignal || [];

OneSignal.push(['init', <%= JSON.stringify(options.onsOpts, null, 2) %>]);
OneSignal.push(['init', <%= JSON.stringify(options.init, null, 2) %>]);

export default function (ctx, inject) {
inject('OneSignal', OneSignal)
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module.exports = {
]
},
oneSignal: {
appId: 'd867ac26-f7be-4c62-9fdd-b756a33c4a8f'
init: {
appId: 'd867ac26-f7be-4c62-9fdd-b756a33c4a8f'
}
}
}

0 comments on commit dd61c18

Please sign in to comment.