-
Notifications
You must be signed in to change notification settings - Fork 1
/
DejaVuex.vue
58 lines (57 loc) · 1.64 KB
/
DejaVuex.vue
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
48
49
50
51
52
53
54
55
56
57
58
<script>
import { createAll } from '@/libs/deja-vuex';
export default {
props: {
limit: {
type: Number,
default: 20,
},
include: {
type: Function,
default: () => true,
},
objectHash: {
type: Function,
default: null,
},
},
created() {
// Register module on created so mounted can watch getter
const { namespace, register } = createAll({
store: this.$store,
limit: this.$options.propsData.limit,
include: this.$options.propsData.include,
objectHash: this.objectHash,
});
register();
this.namespace = namespace;
this.$store.dispatch(`${this.namespace}/record`);
},
mounted() {
// Emit cursor change event
this.$watch(
() => this.$store.getters[`${this.namespace}/getCursor`],
(cursor) => this.$emit('cursorChanged', cursor),
);
},
destroyed() {
this.$store.dispatch(`${this.namespace}/stop`);
this.$store.unregisterModule(this.namespace);
},
render(h) {
return h(
'div',
this.$scopedSlots.default({
getHistory: this.$store.getters[`${this.namespace}/getHistory`],
getCursor: this.$store.getters[`${this.namespace}/getCursor`],
canUndo: this.$store.getters[`${this.namespace}/canUndo`],
canRedo: this.$store.getters[`${this.namespace}/canRedo`],
undo: () => this.$store.dispatch(`${this.namespace}/undo`),
redo: () => this.$store.dispatch(`${this.namespace}/redo`),
travel: (id) => this.$store.dispatch(`${this.namespace}/travel`, id),
reapply: (id) => this.$store.dispatch(`${this.namespace}/reapply`, id),
}),
);
},
};
</script>