Skip to content

Commit

Permalink
refactor: Utils and constants files
Browse files Browse the repository at this point in the history
  • Loading branch information
ktquez committed Jun 7, 2020
1 parent c172e4d commit 736d677
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
34 changes: 16 additions & 18 deletions src/VueDisqus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

<script>
import {
callbacks,
getEmitName,
allowedSSOKeys,
allowedPageConfigKeys
} from './utils'
SSO_KEYS,
CALLBACKS,
PAGE_CONFIG_KEYS
} from './constants'
import { getEmitName } from './utils'
export default {
name: 'VueDisqus',
Expand All @@ -21,12 +21,12 @@ export default {
pageConfig: {
type: Object,
required: false,
validator: config => Object.keys(config).every(key => allowedPageConfigKeys.includes(key))
validator: config => Object.keys(config).every(key => PAGE_CONFIG_KEYS.includes(key))
},
ssoConfig: {
type: Object,
required: false,
validator: config => Object.keys(config).every(key => allowedSSOKeys.includes(key))
validator: config => Object.keys(config).every(key => SSO_KEYS.includes(key))
},
lang: {
type: String
Expand Down Expand Up @@ -99,16 +99,14 @@ export default {
},
makeEmbedScript () {
setTimeout(() => {
const d = document
const s = d.createElement('script')
s.setAttribute('id', 'embed-disqus')
s.setAttribute('data-timestamp', +new Date())
s.type = 'text/javascript'
s.async = true
s.src = `//${this.shortname}.disqus.com/embed.js`
;(d.head || d.body).appendChild(s)
}, 0)
const d = document
const s = d.createElement('script')
s.setAttribute('id', 'embed-disqus')
s.setAttribute('data-timestamp', +new Date())
s.type = 'text/javascript'
s.async = true
s.src = `//${this.shortname}.disqus.com/embed.js`
;(d.head || d.body).appendChild(s)
},
setBaseConfig (disqusConfig) {
Expand Down Expand Up @@ -138,7 +136,7 @@ export default {
},
cbDisqus (disqusConfig) {
callbacks.forEach(cb => {
CALLBACKS.forEach(cb => {
disqusConfig.callbacks[cb] = [e => {
this.$emit(getEmitName(cb), e)
}]
Expand Down
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const PAGE_CONFIG_KEYS = ['api_key', 'author_s3', 'category_id', 'identifier', 'integration', 'language', 'remote_auth_s3', 'slug', 'title', 'url']
export const SSO_KEYS = ['name', 'button', 'icon', 'url', 'logout', 'width', 'height']
export const CALLBACKS = ['afterRender', 'onInit', 'onIdentify', 'beforeComment', 'onNewComment', 'onPaginate', 'onReady', 'preData', 'preInit', 'preReset']
4 changes: 0 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export const allowedPageConfigKeys = ['api_key', 'author_s3', 'category_id', 'identifier', 'integration', 'language', 'remote_auth_s3', 'slug', 'title', 'url']
export const allowedSSOKeys = ['name', 'button', 'icon', 'url', 'logout', 'width', 'height']
export const callbacks = ['afterRender', 'onInit', 'onIdentify', 'beforeComment', 'onNewComment', 'onPaginate', 'onReady', 'preData', 'preInit', 'preReset']

export const getEmitName = str => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase().replace('on-', '')

0 comments on commit 736d677

Please sign in to comment.