Passed
Push — master ( 967bc6...fd5993 )
by Vinicius
02:44
created

index.js ➔ ???   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 1
ccs 1
cts 1
cp 1
crap 3
rs 10
c 0
b 0
f 0
1 2
import mixin from './mixin'
2 2
import { setPageTitle } from './page-title'
3 2
import { setup as setupRouter } from './router'
4
5 2
const install = (Vue, options = {}) => {
6
  // prevent double install
7
  /* istanbul ignore next */
8
  if (install.installed) return
9 5
  install.installed = true
10
11
  // title state
12 5
  const $page = {
13
    title: ''
14
  }
15
16 5
  const setTitle = value => {
17 10
    setPageTitle(value, options)
18 10
    $page.title = value
19
  }
20
21
  // make reactive title
22 5
  Vue.util.defineReactive($page, 'title', '')
23
24
  // add title to component context
25 5
  Object.defineProperty(Vue.prototype, '$title', {
26 21
    get: () => $page.title,
27 9
    set: value => setTitle(value)
28
  })
29
30
  // vue router support
31 5
  if (options.router) {
32 1
    setupRouter(setTitle, options)
33
  }
34
35
  // add global mixin
36 5
  Vue.mixin(mixin)
37
}
38
39 2
const VuePageTitle = { install }
40
41
export { install }
42
export default VuePageTitle
43