-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
46 lines (40 loc) · 791 Bytes
/
index.js
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
export default {
props: {
mapDispatchToProps: {
required: false,
default: () => ({}),
type: Function,
},
mapStateToProps: {
required: false,
default: () => ({}),
type: Function,
},
store: {
required: true,
type: Object,
},
},
data: ctx => ({
state: ctx.store.getState(),
}),
created() {
this.unsubscribe = this.store.subscribe(() => {
this.state = this.store.getState()
})
},
destroyed() {
this.unsubscribe()
},
render() {
const nodes = this.$scopedSlots.default({
...this.mapDispatchToProps(this.store.dispatch),
...this.mapStateToProps(this.state),
})
if (Array.isArray(nodes)) {
return nodes[0]
} else {
return nodes
}
},
}