Skip to content

Commit 8203fe2

Browse files
Loading of movie examples
1 parent 6e23717 commit 8203fe2

File tree

2 files changed

+74
-35
lines changed

2 files changed

+74
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
test/screenshots
44
test/videos
55
.build
6+
.idea

examples/vuejs/App.vue

Lines changed: 73 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,93 @@
11

22
<template>
3-
<div class="movies">
4-
<div class="movie" v-for="movie in movies" :key="movie.id">
5-
<img :src="movie.img"/>
6-
</div>
3+
<div>
4+
<div class="movies">
5+
<div class="movie" v-for="movie in movies" :key="movie.id">
6+
<img :src="movie.img"/>
7+
</div>
8+
</div>
9+
<a @click="nextHandler()" class="next">Next</a>
710
</div>
811
</template>
912

1013
<script lang="ts">
1114
import Vue from "vue";
1215
import InfiniteAjaxScroll from '@webcreate/infinite-ajax-scroll';
1316
17+
const catalog = [
18+
{
19+
title: "The Matrix",
20+
img: "https://media-cache.cinematerial.com/p/500x/uq49lqmo/the-matrix-movie-poster.jpg?v=1548664065"
21+
},
22+
{
23+
title: "Jurrasic Park",
24+
img: "https://media-cache.cinematerial.com/p/500x/4ubyv2go/jurassic-park-movie-poster.jpg?v=1456328203"
25+
},
26+
{
27+
title: "Indiana Jones",
28+
img: "https://cdn.shopify.com/s/files/1/0057/3728/3618/products/609df06d7c2b5fb3125f16a7e4e34152_592ed277-d9d9-4400-af4b-f793370e5f54_480x.progressive.jpg?v=1573616163"
29+
},
30+
{
31+
title: "2001, A space odyssey",
32+
img: "https://cdn.shopify.com/s/files/1/1416/8662/products/2001_a_space_odyssey_french_grande_linen_original_film_art_f_1200x.jpg?v=1587685085"
33+
}
34+
]
35+
36+
let ias = null;
37+
1438
export default Vue.extend({
1539
data() {
1640
return {
17-
movies: [
18-
{
19-
id: 1,
20-
title: "The Matrix",
21-
img: "https://media-cache.cinematerial.com/p/500x/uq49lqmo/the-matrix-movie-poster.jpg?v=1548664065"
22-
},
23-
{
24-
id: 2,
25-
title: "Jurrasic Park",
26-
img: "https://media-cache.cinematerial.com/p/500x/4ubyv2go/jurassic-park-movie-poster.jpg?v=1456328203"
27-
},
28-
{
29-
id: 3,
30-
title: "Indiana Jones",
31-
img: "https://cdn.shopify.com/s/files/1/0057/3728/3618/products/609df06d7c2b5fb3125f16a7e4e34152_592ed277-d9d9-4400-af4b-f793370e5f54_480x.progressive.jpg?v=1573616163"
32-
}
33-
]
41+
movies: []
3442
};
3543
},
3644
mounted() {
37-
window.ias = new InfiniteAjaxScroll('.movies', {
38-
item: '.movie',
39-
next: () => {
40-
console.log("Next")
41-
},
42-
pagination: false,
43-
bind: false
44-
});
45-
46-
setTimeout(() => {
47-
ias.bind();
48-
}, 5000)
45+
// Simulate initial load
46+
Promise.all([
47+
this.loadNewMovie(),
48+
this.loadNewMovie(),
49+
this.loadNewMovie(),
50+
this.loadNewMovie()
51+
]).then(() => {
52+
ias = new InfiniteAjaxScroll('.movies', {
53+
item: '.movie',
54+
pagination: false,
55+
});
56+
57+
ias.on('hit', () => {
58+
console.log("hit!!!")
59+
this.loadNewMovie()
60+
})
61+
})
62+
},
63+
methods: {
64+
loadNewMovie() {
65+
return new Promise((resolve) => {
66+
// Simulate loading of new movie
67+
setTimeout(() => {
68+
const index = Math.round((Math.random() * (catalog.length - 1)));
69+
const movie = {...catalog[index], id: this.movies.length + 1 };
70+
71+
this.movies.push(movie)
72+
resolve()
73+
}, 2000)
74+
})
75+
},
76+
nextHandler() {
77+
this.loadNewMovie()
78+
}
4979
}
5080
});
5181
</script>
5282

5383
<style lang="scss" scoped>
54-
55-
</style>
84+
.movie {
85+
margin: 20px 0;
86+
padding: 20px 20px;
87+
width: 300px;
88+
background-color: #ff0000;
89+
img {
90+
width: 100%;
91+
}
92+
}
93+
</style>

0 commit comments

Comments
 (0)