Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

foxbenjaminfox / vue-async-computed / 59

17 Mar 20 - 13:17 coverage decreased (-5.6%) to 94.444%
# 59

push

travis-ci

Dade449ea5213a97815aa0f39e57bdec?size=18&default=identiconfoxbenjaminfox
Merge branch 'master' of github.com:foxbenjaminfox/vue-async-computed

18.0 hits per line

34 of 36 relevant lines covered (94.44%)

29 of 36 branches covered (80.56%)

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/index.js
1
const prefix = '_async_computed$'
2×
2

3
const AsyncComputed = {
2×
4
  install (Vue, options) {
5
    options = options || {}
Branches [[4, 1]] missed. 2×
6

7
    Vue.config
2×
8
      .optionMergeStrategies
9
      .asyncComputed = Vue.config.optionMergeStrategies.computed
10

11
    Vue.mixin({
2×
12
      beforeCreate () {
13
        const optionData = this.$options.data
22×
14

15
        if (!this.$options.computed) this.$options.computed = {}
22×
16

17
        Object.keys(this.$options.asyncComputed || {}).forEach(key => {
22×
18
          const fn = this.$options.asyncComputed[key],
34×
19
                get = typeof fn === 'function' ? fn : fn.get
20

21
          this.$options.computed[prefix + key] = get
34×
22
        })
23

24
        this.$options.data = function vueAsyncComputedInjectedDataFn () {
22×
25
          const data = (
22×
26
              (typeof optionData === 'function')
27
                ? optionData.call(this)
28
                : optionData
29
             ) || {}
30
          Object.keys(this.$options.asyncComputed || {}).forEach(key => {
22×
31
            data[key] = null
34×
32
          })
33
          return data
22×
34
        }
35
      },
36
      created () {
37
        Object.keys(this.$options.asyncComputed || {}).forEach(key => {
22×
38
          const fn = this.$options.asyncComputed[key],
34×
39
                def = typeof fn.default === 'undefined' ? null : fn.default
40

41
          if (typeof def === 'function') {
34×
42
            this[key] = def.call(this)
4×
43
          } else {
44
            this[key] = def
30×
45
          }
46
        })
47

48
        Object.keys(this.$options.asyncComputed || {}).forEach(key => {
22×
49
          let promiseId = 0
34×
50
          this.$watch(prefix + key, newPromise => {
34×
51
            const thisPromise = ++promiseId
40×
52
            newPromise.then(value => {
40×
53
              if (thisPromise !== promiseId) return
38×
54
              this[key] = value
36×
55
            }).catch(err => {
56
              if (thisPromise !== promiseId) return
Branches [[16, 0]] missed. 2×
57

58
              if (options.errorHandler === false) return
Branches [[17, 0]] missed. 2×
59

60
              const handler = (options.errorHandler === undefined)
2×
61
                ? console.error.bind(console, 'Error evaluating async computed property:')
Branches [[18, 0]] missed.
62
                : options.errorHandler
63

64
              if (options.useRawError) {
Branches [[19, 1]] missed. 2×
65
                handler(err)
2×
66
              } else {
67
                handler(err.stack)
!
68
              }
69
            })
70
          }, { immediate: true })
71
        })
72
      }
73
    })
74
  }
75
}
76

77
export default AsyncComputed
2×
78

79
// Auto install in dist mode
80
if (typeof window !== 'undefined' && window.Vue) {
Branches [[20, 0], [21, 1]] missed. 2×
81
  window.Vue.use(AsyncComputed)
!
82
}
Troubleshooting · Open an Issue · Sales · FEEDBACK · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2017 Lemur Heavy Industries