<template>
  <div>{{value | json}}</div>
</template>

<script lang="babel">
  import Vue from 'vue'
  export default {
    init () {
      if (this.$parent.pokeCache === undefined) {
        Vue.set(this.$parent, 'pokeCache', {})
      }
    },
    created () {
      if (this.$parent.pokeCache[this.value] === undefined) {
        Vue.set(
          this.$parent.pokeCache,
          this.value,
          'loading...'
        )
        this.$http.get('//pokeapi.co/api/v2/pokemon/' +
          this.value.name).then(response => {
            Vue.set(this, 'items', response.json().sprites.front_default)
          })
      } else {
        this.value.items = this.$parent.pokeCache[this.value]
      }
    }
  }
</script>
