File tree Expand file tree Collapse file tree 3 files changed +17
-11
lines changed Expand file tree Collapse file tree 3 files changed +17
-11
lines changed Original file line number Diff line number Diff line change 12
12
"devDependencies" : {
13
13
"@rollup/plugin-commonjs" : " 25.0.7" ,
14
14
"@rollup/plugin-json" : " 6.1.0" ,
15
- "@rollup/plugin-wasm" : " 6.2.2" ,
16
15
"@rollup/plugin-node-resolve" : " 15.2.3" ,
17
16
"@rollup/plugin-terser" : " 0.4.4" ,
18
17
"@rollup/plugin-typescript" : " 11.1.5" ,
18
+ "@rollup/plugin-wasm" : " 6.2.2" ,
19
19
"@tsconfig/svelte" : " 5.0.2" ,
20
20
"@types/human-date" : " ^1.4.0" ,
21
21
"autoprefixer" : " 10.4.13" ,
Original file line number Diff line number Diff line change 42
42
} catch {}
43
43
searching = false ;
44
44
debouncedQuery = query ;
45
- }, 500 );
45
+ }, 0 );
46
46
47
47
$ : searching = debouncedQuery !== query ;
48
48
$ : {
Original file line number Diff line number Diff line change @@ -10,6 +10,19 @@ export interface GeocodeResult {
10
10
type : string ;
11
11
}
12
12
13
+ let initPromise : Promise < typeof import ( 'nz-search' ) > ;
14
+ function getSearch ( ) {
15
+ if ( ! initPromise ) {
16
+ initPromise = ( async ( ) => {
17
+ const [ places , searchApi ] = await Promise . all ( [ ( await fetch ( 'data/places.json' ) ) . arrayBuffer ( ) , import ( 'nz-search' ) ] )
18
+ await searchApi . default ( )
19
+ searchApi . load_data ( new Uint8Array ( places ) )
20
+ return searchApi
21
+ } ) ( )
22
+ }
23
+ return initPromise
24
+ }
25
+
13
26
const searchOsm = async ( query : string ) : Promise < GeocodeResult [ ] > => {
14
27
// Hackily include the country because the nominatim API is terrible.
15
28
query = query + ", NZ" ;
@@ -23,17 +36,10 @@ const searchOsm = async (query: string): Promise<GeocodeResult[]> => {
23
36
}
24
37
25
38
const searchNzPlaces = async ( query : string ) : Promise < GeocodeResult [ ] > => {
26
- const api = await import ( 'nz-search' ) . then ( async search => {
27
- await search . default ( ) ;
28
- return search
29
- } )
39
+ const api = await getSearch ( )
30
40
31
- const results = api . search ( query )
41
+ const results = api . search ( query , 100 )
32
42
return results
33
- // const url = `${nzPlacesUrl}?query=${encodeURIComponent(query)}`;
34
- // const response = await fetch(url);
35
- // const data = await response.json();
36
- // return data;
37
43
}
38
44
39
45
export default async ( query : string , sources = [ searchNzPlaces ] ) : Promise < GeocodeResult [ ] > => {
You can’t perform that action at this time.
0 commit comments