@@ -19,11 +19,6 @@ extern "C" {
19
19
fn initialize ( lat : f64 , lon : f64 ) ;
20
20
}
21
21
22
- #[ wasm_bindgen]
23
- extern "C" {
24
- fn alert ( s : & str ) ;
25
- }
26
-
27
22
// This is like the `main` function, except for JavaScript.
28
23
#[ wasm_bindgen( start) ]
29
24
pub fn main_js ( ) -> Result < ( ) , JsValue > {
@@ -36,7 +31,11 @@ pub fn main_js() -> Result<(), JsValue> {
36
31
let input_box = create_input_box ( & document) ;
37
32
search_div. append_child ( & input_box) ?;
38
33
let submit_box = create_submit_box ( & document) ;
39
- let temp_div = create_div ( & document, "tempDetail" , "ReportStyles-mainContainer col-md-12 maincontainer" ) ;
34
+ let temp_div = create_div (
35
+ & document,
36
+ "tempDetail" ,
37
+ "ReportStyles-mainContainer col-md-12 maincontainer" ,
38
+ ) ;
40
39
let first_div = document. create_element ( "div" ) ?;
41
40
let second_div = create_div ( & document, "second_div" , "col-md-6" ) ;
42
41
let third_div = create_div ( & document, "third_div" , "ReportStyles-innerDiv" ) ;
@@ -191,11 +190,15 @@ pub fn main_js() -> Result<(), JsValue> {
191
190
} ) ;
192
191
} ) ;
193
192
193
+ // When a Closure is dropped it will invalidate the associated JS closure.
194
+ // Here we want JS callback to be alive for the entire duration of the program.
195
+ // So we used `forget` leak this instance of Closure.
196
+ // It should be used sparingly to ensure the memory leak doesn't affect the program too much.
194
197
on_click. forget ( ) ;
195
198
Ok ( ( ) )
196
199
}
197
200
198
- fn create_div ( document : & Document , id : & str , class : & str ) -> Element {
201
+ fn create_div ( document : & Document , id : & str , class : & str ) -> Element {
199
202
let div = document. create_element ( "div" ) . unwrap ( ) ;
200
203
div. set_id ( id) ;
201
204
div. set_class_name ( class) ;
@@ -226,7 +229,7 @@ fn create_input_box(document: &Document) -> Element {
226
229
// Get response from weather api
227
230
async fn get_response ( location : & str ) -> JsonValue {
228
231
let url1 = "http://api.openweathermap.org/data/2.5/weather?q=" ;
229
- let url2 = "&appid=<apikey >" ;
232
+ let url2 = "&appid=<apiKey >" ;
230
233
231
234
let url = [ url1, location, url2] . concat ( ) ;
232
235
0 commit comments