1
// Utilities
2
import { removed } from '../../util/console'
3

4
// Types
5
import Vue, { VNode } from 'vue'
6
interface Toggleable extends Vue {
7
  isActive?: boolean
8
}
9

10
/**
11
 * Bootable
12
 * @mixin
13
 *
14
 * Used to add lazy content functionality to components
15
 * Looks for change in "isActive" to automatically boot
16
 * Otherwise can be set manually
17
 */
18
/* @vue/component */
19
export default Vue.extend<Vue & Toggleable>().extend({
20
  name: 'bootable',
21

22
  props: {
23
    eager: Boolean,
24
  },
25

26 1
  data: () => ({
27
    isBooted: false,
28
  }),
29

30
  computed: {
31 1
    hasContent (): boolean | undefined {
32 1
      return this.isBooted || this.eager || this.isActive
33
    },
34
  },
35

36
  watch: {
37 1
    isActive () {
38 1
      this.isBooted = true
39
    },
40
  },
41

42 1
  created () {
43
    /* istanbul ignore next */
44
    if ('lazy' in this.$attrs) {
45
      removed('lazy', this)
46
    }
47
  },
48

49
  methods: {
50 1
    showLazyContent (content?: () => VNode[]): VNode[] {
51 1
      return (this.hasContent && content) ? content() : [this.$createElement()]
52
    },
53
  },
54
})

Read our documentation on viewing source code .

Loading