tpage
2018-06-19 c16ddc4e070b30692a471bd7250a10815d6825de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<template>
    <div>
        <div class="xofyDone">
            <span> {{sumDoneTodoItems(todos)}} out of {{this.todos.length}} done. </span>
            <md-button class="md-raised" v-on:click="clearDoneTodos()">Clear Done</md-button>
            <md-button class="md-raised" v-on:click="clearTodos()">Clear all</md-button>
        </div>
    </div>
</template>
 
<script>
import { mapGetters } from "vuex";
 
export default {
  name: "XofYItems",
  computed: {
    ...mapGetters(["todos"])
  },
  created() {
    this.$store.dispatch("loadTodos");
  },
  methods: {
    clearDoneTodos() {
      this.$store.dispatch("clearTodos");
    },
    clearTodos() {
      // NOTE - true = all todos
      this.$store.dispatch("clearTodos", true);
    },
    sumDoneTodoItems(todos) {
      return todos.reduce(
        (result, tdItem) => (tdItem.completed ? result + 1 : result),
        0
      );
    }
  }
};
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.xofyDone {
  height: 52px;
  line-height: 52px;
  display: inline-block;
}
</style>