/**
 * Change title on route
 */
import router from '../router'
import store from '../store'

export default (Vue, options) => {
  let items

  router.afterEach(route => {
    items = route.matched
      .map(item => item.components.default[options.property] || item.components.default.name)
      .reverse()
    store.dispatch('changeTitle', items.join(options.separator))
  })

  // partial
  Object.defineProperties(Vue.prototype, {
    $title: {
      get: () => (title, fullname) => {
        if (fullname) {
          store.dispatch('changeTitle', title)
        } else {
          items[0] = title
          store.dispatch('changeTitle', items.join(options.separator))
        }
      }
    }
  })
}

@@ -22,16 +22,36 @@
 n route%0A
+ * TODO: title case%0A
  */%0Aimpo
@@ -230,16 +230,17 @@
 item =%3E 
+(
 item.com
@@ -305,16 +305,31 @@
 lt.name)
+.toUpperCase())
 %0A      .
@@ -588,16 +588,30 @@
 ', title
+.toUpperCase()
 )%0A      
@@ -647,16 +647,30 @@
  = title
+.toUpperCase()
 %0A       

Change demo title cast