File tree 2 files changed +41
-0
lines changed 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -87,3 +87,5 @@ buck-out/
87
87
web-build /
88
88
89
89
# @end expo-cli
90
+
91
+ ! lib
Original file line number Diff line number Diff line change
1
+ import movies from '../data/movies.json' ;
2
+
3
+ export type Movie = {
4
+ title : string ;
5
+ year : number ;
6
+ } ;
7
+
8
+ export type MovieDetails = Movie & {
9
+ info : {
10
+ plot : string ;
11
+ actors : string [ ] ;
12
+ } ;
13
+ } ;
14
+
15
+ function delay ( t : number , v : ( ) => void ) {
16
+ return new Promise ( function ( resolve ) {
17
+ setTimeout ( resolve . bind ( null , v ) , t ) ;
18
+ } ) ;
19
+ }
20
+
21
+ export async function fetchMovies ( ) {
22
+ console . log ( 'fetchMovies' ) ;
23
+ return delay ( 200 + Math . floor ( Math . random ( ) * 2000 ) , ( ) =>
24
+ movies
25
+ . slice ( 0 , 100 )
26
+ . map ( ( movie ) => ( { title : movie . title , year : movie . year } ) )
27
+ ) as Promise < Movie [ ] > ;
28
+ }
29
+
30
+ export async function fetchMovie ( title : string ) {
31
+ console . log ( 'fetchMovie' , title ) ;
32
+ return delay ( 200 + Math . floor ( Math . random ( ) * 2000 ) , ( ) => {
33
+ const result = movies . filter ( ( item ) => item . title === title ) ;
34
+ if ( result . length == 0 ) {
35
+ throw new Error ( 'Movie not found' ) ;
36
+ }
37
+ return result [ 0 ] ;
38
+ } ) as Promise < MovieDetails > ;
39
+ }
You can’t perform that action at this time.
0 commit comments