diff --git a/src/client/refresh.js b/src/client/refresh.js
index 8567fd0..3bfa33e 100644
--- a/src/client/refresh.js
+++ b/src/client/refresh.js
@@ -1,18 +1,20 @@
import getMetaInfo from '../shared/getMetaInfo'
import updateClientMetaInfo from './updateClientMetaInfo'
-/**
- * When called, will update the current meta info with new meta info.
- * Useful when updating meta info as the result of an asynchronous
- * action that resolves after the initial render takes place.
- *
- * Credit to [Sébastien Chopin](https://github.com/Atinux) for the suggestion
- * to implement this method.
- *
- * @return {Object} - new meta info
- */
-export default function refresh () {
- const info = getMetaInfo(this.$root)
- updateClientMetaInfo(info)
- return info
+export default function _refresh (options) {
+ /**
+ * When called, will update the current meta info with new meta info.
+ * Useful when updating meta info as the result of an asynchronous
+ * action that resolves after the initial render takes place.
+ *
+ * Credit to [Sébastien Chopin](https://github.com/Atinux) for the suggestion
+ * to implement this method.
+ *
+ * @return {Object} - new meta info
+ */
+ return function refresh () {
+ const info = getMetaInfo(options)(this.$root)
+ updateClientMetaInfo(options)(info)
+ return info
+ }
}
diff --git a/src/client/updateClientMetaInfo.js b/src/client/updateClientMetaInfo.js
index f32e011..d6b1243 100644
--- a/src/client/updateClientMetaInfo.js
+++ b/src/client/updateClientMetaInfo.js
@@ -1,53 +1,56 @@
import updateTitle from './updaters/updateTitle'
import updateTagAttributes from './updaters/updateTagAttributes'
import updateTags from './updaters/updateTags'
-import { SERVER_RENDERED_ATTRIBUTE } from '../shared/constants'
-/**
- * Performs client-side updates when new meta info is received
- *
- * @param {Object} newInfo - the meta info to update to
- */
-export default function updateClientMetaInfo (newInfo) {
- const htmlTag = document.getElementsByTagName('html')[0]
- // if this is not a server render, then update
- if (htmlTag.getAttribute(SERVER_RENDERED_ATTRIBUTE) === null) {
- // initialize tracked changes
- const addedTags = {}
- const removedTags = {}
+export default function _updateClientMetaInfo (options) {
+ const { ssrAttribute } = options
- Object.keys(newInfo).forEach((key) => {
- switch (key) {
- // update the title
- case 'title':
- updateTitle(newInfo.title)
- break
- // update attributes
- case 'htmlAttrs':
- case 'bodyAttrs':
- updateTagAttributes(newInfo[key], key === 'htmlAttrs' ? htmlTag : document.getElementsByTagName('body')[0])
- break
- // ignore these
- case 'titleChunk':
- case 'titleTemplate':
- case 'changed':
- break
- // catch-all update tags
- default:
- const { oldTags, newTags } = updateTags(key, newInfo[key], document.getElementsByTagName('head')[0])
- if (newTags.length) {
- addedTags[key] = newTags
- removedTags[key] = oldTags
- }
+ /**
+ * Performs client-side updates when new meta info is received
+ *
+ * @param {Object} newInfo - the meta info to update to
+ */
+ return function updateClientMetaInfo (newInfo) {
+ const htmlTag = document.getElementsByTagName('html')[0]
+ // if this is not a server render, then update
+ if (htmlTag.getAttribute(ssrAttribute) === null) {
+ // initialize tracked changes
+ const addedTags = {}
+ const removedTags = {}
+
+ Object.keys(newInfo).forEach((key) => {
+ switch (key) {
+ // update the title
+ case 'title':
+ updateTitle(options)(newInfo.title)
+ break
+ // update attributes
+ case 'htmlAttrs':
+ case 'bodyAttrs':
+ updateTagAttributes(options)(newInfo[key], key === 'htmlAttrs' ? htmlTag : document.getElementsByTagName('body')[0])
+ break
+ // ignore these
+ case 'titleChunk':
+ case 'titleTemplate':
+ case 'changed':
+ break
+ // catch-all update tags
+ default:
+ const { oldTags, newTags } = updateTags(options)(key, newInfo[key], document.getElementsByTagName('head')[0])
+ if (newTags.length) {
+ addedTags[key] = newTags
+ removedTags[key] = oldTags
+ }
+ }
+ })
+
+ // emit "event" with new info
+ if (typeof newInfo.changed === 'function') {
+ newInfo.changed(newInfo, addedTags, removedTags)
}
- })
-
- // emit "event" with new info
- if (typeof newInfo.changed === 'function') {
- newInfo.changed(newInfo, addedTags, removedTags)
+ } else {
+ // remove the server render attribute so we can update on changes
+ htmlTag.removeAttribute(ssrAttribute)
}
- } else {
- // remove the server render attribute so we can update on changes
- htmlTag.removeAttribute(SERVER_RENDERED_ATTRIBUTE)
}
}
diff --git a/src/client/updaters/updateTagAttributes.js b/src/client/updaters/updateTagAttributes.js
index cf19641..b413b5d 100644
--- a/src/client/updaters/updateTagAttributes.js
+++ b/src/client/updaters/updateTagAttributes.js
@@ -1,35 +1,35 @@
-import { VUE_META_ATTRIBUTE } from '../../shared/constants'
-
-/**
- * updates the document's html tag attributes
- *
- * @param {Object} attrs - the new document html attributes
- * @param {HTMLElement} tag - the HTMLElment tag to update with new attrs
- */
-export default function updateTagAttributes (attrs, tag) {
- const vueMetaAttrString = tag.getAttribute(VUE_META_ATTRIBUTE)
- const vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : []
- const toRemove = [].concat(vueMetaAttrs)
- for (let attr in attrs) {
- if (attrs.hasOwnProperty(attr)) {
- const val = attrs[attr] || ''
- tag.setAttribute(attr, val)
- if (vueMetaAttrs.indexOf(attr) === -1) {
- vueMetaAttrs.push(attr)
- }
- const saveIndex = toRemove.indexOf(attr)
- if (saveIndex !== -1) {
- toRemove.splice(saveIndex, 1)
+export default function _updateTagAttributes ({ attribute }) {
+ /**
+ * updates the document's html tag attributes
+ *
+ * @param {Object} attrs - the new document html attributes
+ * @param {HTMLElement} tag - the HTMLElment tag to update with new attrs
+ */
+ return function updateTagAttributes (attrs, tag) {
+ const vueMetaAttrString = tag.getAttribute(attribute)
+ const vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : []
+ const toRemove = [].concat(vueMetaAttrs)
+ for (let attr in attrs) {
+ if (attrs.hasOwnProperty(attr)) {
+ const val = attrs[attr] || ''
+ tag.setAttribute(attr, val)
+ if (vueMetaAttrs.indexOf(attr) === -1) {
+ vueMetaAttrs.push(attr)
+ }
+ const saveIndex = toRemove.indexOf(attr)
+ if (saveIndex !== -1) {
+ toRemove.splice(saveIndex, 1)
+ }
}
}
- }
- let i = toRemove.length - 1
- for (; i >= 0; i--) {
- tag.removeAttribute(toRemove[i])
- }
- if (vueMetaAttrs.length === toRemove.length) {
- tag.removeAttribute(VUE_META_ATTRIBUTE)
- } else {
- tag.setAttribute(VUE_META_ATTRIBUTE, vueMetaAttrs.join(','))
+ let i = toRemove.length - 1
+ for (; i >= 0; i--) {
+ tag.removeAttribute(toRemove[i])
+ }
+ if (vueMetaAttrs.length === toRemove.length) {
+ tag.removeAttribute(attribute)
+ } else {
+ tag.setAttribute(attribute, vueMetaAttrs.join(','))
+ }
}
}
diff --git a/src/client/updaters/updateTags.js b/src/client/updaters/updateTags.js
index 3db1dbd..82f6b45 100644
--- a/src/client/updaters/updateTags.js
+++ b/src/client/updaters/updateTags.js
@@ -1,59 +1,59 @@
-import { VUE_META_ATTRIBUTE } from '../../shared/constants'
-
// borrow the slice method
const toArray = Function.prototype.call.bind(Array.prototype.slice)
-/**
- * Updates meta tags inside
on the client. Borrowed from `react-helmet`:
- * https://github.com/nfl/react-helmet/blob/004d448f8de5f823d10f838b02317521180f34da/src/Helmet.js#L195-L245
- *
- * @param {('meta'|'base'|'link'|'style'|'script'|'noscript')} type - the name of the tag
- * @param {(Array