8000 refactor: use template for list view and utilize $listeners and $attrs · lemonwong/nativescript-vue@1fa9b04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1fa9b04

Browse files
committed
refactor: use template for list view and utilize $listeners and $attrs
1 parent d7646ee commit 1fa9b04

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

platform/nativescript/runtime/components/list-view.js

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ export default {
77
type: Array,
88
required: true
99
},
10-
separatorColor: {
11-
type: String
12-
},
1310
'+alias': {
1411
type: String,
1512
default: 'item'
@@ -19,20 +16,18 @@ export default {
1916
}
2017
},
2118

22-
render(h) {
23-
return h(
24-
'native-list-view',
25-
{
26-
ref: 'listView',
27-
on: this._on,
28-
domProps: {
29-
items: this.items,
30-
separatorColor: this.separatorColor
31-
}
32-
},
33-
this.$slots.default
34-
)
35-
},
19+
template: `
20+
<native-list-view
21+
ref="listView"
22+
:items="items"
23+
v-bind="$attrs"
24+
v-on="listeners"
25+
@itemTap="onItemTap"
26+
@itemLoading="onItemLoading"
27+
>
28+
<slot />
29+
</native-list-view>
30+
`,
3631

3732
watch: {
3833
items: {
@@ -45,17 +40,11 @@ export default {
4540
},
4641

4742
created() {
48-
this._on = {
49-
itemLoading: this.onItemLoading,
50-
itemTap: args =>
51-
this.$emit(
52-
'itemTap',
53-
Object.assign({ item: this.items[args.index] }, args)
54-
),
55-
loaded: args => this.$emit('loaded', args),
56-
unloaded: args => this.$emit('unloaded', args),
57-
loadMoreItems: args => this.$emit('loadMoreItems', args)
58-
}
43+
// we need to remove the itemTap handler from a clone of the $listeners
44+
// object because we are emitting the event ourselves with added data.
45+
const listeners = Object.assign({}, this.$listeners)
46+
delete listeners.itemTap
47+
this.listeners = listeners
5948
},
6049

6150
mounted() {
@@ -73,6 +62,12 @@ export default {
7362
},
7463

7564
methods: {
65+
onItemTap(args) {
66+
this.$emit(
67+
'itemTap',
68+
Object.assign({ item: this.items[args.index] }, args)
69+
)
70+
},
7671
onItemLoading(args) {
7772
const index = args.index
7873
const items = args.object.items

0 commit comments

Comments
 (0)
0