Skip to content

Commit 220c488

Browse files
committed
Cleanup of recent changes to examples
1 parent 46bfb9c commit 220c488

File tree

10 files changed

+59
-36
lines changed

10 files changed

+59
-36
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ enum Msg {
127127
}
128128

129129
/// The sole source of updating the model; returns a fresh one.
130-
fn update(msg: Msg, model: Model) -> Model {
130+
fn update(history: &mut History<Model, Msg>,: Msg, model: Model) -> Model {
131131
match msg {
132132
Msg::Increment => Model {count: model.count + 1, ..model},
133133
Msg::Decrement => Model {count: model.count - 1, ..model},
@@ -189,7 +189,7 @@ fn view(model: Model) -> El<Msg> {
189189

190190
#[wasm_bindgen]
191191
pub fn render() {
192-
seed::run(Model::default(), update, view, "main");
192+
seed::run(Model::default(), update, view, "main", None);
193193
}
194194
```
195195

examples/counter/pkg/counter.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,15 @@ __exports.__widl_f_value_HTMLTextAreaElement = function(ret, arg0) {
268268

269269
};
270270

271-
const __widl_f_back_History_target = typeof History === 'undefined' ? null : History.prototype.back || function() {
272-
throw new Error(`wasm-bindgen: History.back does not exist`);
273-
};
274-
275-
__exports.__widl_f_back_History = function(arg0, exnptr) {
271+
__exports.__widl_f_href_Location = function(ret, arg0, exnptr) {
276272
try {
277-
__widl_f_back_History_target.call(getObject(arg0));
273+
274+
const retptr = passStringToWasm(getObject(arg0).href);
275+
const retlen = WASM_VECTOR_LEN;
276+
const mem = getUint32Memory();
277+
mem[ret / 4] = retptr;
278+
mem[ret / 4 + 1] = retlen;
279+
278280
} catch (e) {
279281
const view = getUint32Memory();
280282
view[exnptr / 4] = 1;
@@ -357,18 +359,6 @@ __exports.__widl_f_length_NodeList = function(arg0) {
357359
return __widl_f_length_NodeList_target.call(getObject(arg0));
358360
};
359361

360-
__exports.__widl_instanceof_PopStateEvent = function(idx) {
361-
return getObject(idx) instanceof PopStateEvent ? 1 : 0;
362-
};
363-
364-
const __widl_f_state_PopStateEvent_target = GetOwnOrInheritedPropertyDescriptor(typeof PopStateEvent === 'undefined' ? null : PopStateEvent.prototype, 'state').get || function() {
365-
throw new Error(`wasm-bindgen: PopStateEvent.state does not exist`);
366-
};
367-
368-
__exports.__widl_f_state_PopStateEvent = function(arg0) {
369-
return addHeapObject(__widl_f_state_PopStateEvent_target.call(getObject(arg0)));
370-
};
371-
372362
__exports.__widl_instanceof_Window = function(idx) {
373363
return getObject(idx) instanceof Window ? 1 : 0;
374364
};
@@ -380,6 +370,10 @@ __exports.__widl_f_document_Window = function(arg0) {
380370

381371
};
382372

373+
__exports.__widl_f_location_Window = function(arg0) {
374+
return addHeapObject(getObject(arg0).location);
375+
};
376+
383377
__exports.__widl_f_history_Window = function(arg0, exnptr) {
384378
try {
385379
return addHeapObject(getObject(arg0).history);
@@ -475,9 +469,7 @@ __exports.__wbindgen_cb_drop = function(i) {
475469
return 0;
476470
};
477471

478-
__exports.__wbindgen_cb_forget = dropObject;
479-
480-
__exports.__wbindgen_closure_wrapper790 = function(a, b, _ignored) {
472+
__exports.__wbindgen_closure_wrapper931 = function(a, b, _ignored) {
481473
const f = wasm.__wbg_function_table.get(6);
482474
const d = wasm.__wbg_function_table.get(7);
483475
const cb = function(arg0) {

examples/counter/pkg/counter_bg.wasm

43.5 KB
Binary file not shown.

examples/counter/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ enum Msg {
3535
}
3636

3737
/// The sole source of updating the model; returns a fresh one.
38-
fn update(history: &History<Model, Msg>, msg: Msg, model: Model) -> Model {
38+
fn update(history: &mut History<Model, Msg>, msg: Msg, model: Model) -> Model {
3939
match msg {
4040
Msg::Increment => Model {count: model.count + 1, ..model},
4141
Msg::Decrement => Model {count: model.count - 1, ..model},

examples/server_interaction/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
## Communicating with a server
2+
## Does not work yet
23
Using web-sys's Fetch, and Serde's [de]serializiation.
3-
4-
Does not work yet.

examples/todomvc/pkg/todomvc.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ __exports.__widl_f_key_code_KeyboardEvent = function(arg0) {
297297
return __widl_f_key_code_KeyboardEvent_target.call(getObject(arg0));
298298
};
299299

300+
__exports.__widl_f_href_Location = function(ret, arg0, exnptr) {
301+
try {
302+
303+
const retptr = passStringToWasm(getObject(arg0).href);
304+
const retlen = WASM_VECTOR_LEN;
305+
const mem = getUint32Memory();
306+
mem[ret / 4] = retptr;
307+
mem[ret / 4 + 1] = retlen;
308+
309+
} catch (e) {
310+
const view = getUint32Memory();
311+
view[exnptr / 4] = 1;
312+
view[exnptr / 4 + 1] = addHeapObject(e);
313+
314+
}
315+
};
316+
300317
const __widl_f_append_child_Node_target = typeof Node === 'undefined' ? null : Node.prototype.appendChild || function() {
301318
throw new Error(`wasm-bindgen: Node.appendChild does not exist`);
302319
};
@@ -399,6 +416,21 @@ __exports.__widl_f_document_Window = function(arg0) {
399416

400417
};
401418

419+
__exports.__widl_f_location_Window = function(arg0) {
420+
return addHeapObject(getObject(arg0).location);
421+
};
422+
423+
__exports.__widl_f_history_Window = function(arg0, exnptr) {
424+
try {
425+
return addHeapObject(getObject(arg0).history);
426+
} catch (e) {
427+
const view = getUint32Memory();
428+
view[exnptr / 4] = 1;
429+
view[exnptr / 4 + 1] = addHeapObject(e);
430+
431+
}
432+
};
433+
402434
__exports.__widl_f_local_storage_Window = function(arg0, exnptr) {
403435
try {
404436

@@ -497,7 +529,7 @@ __exports.__wbindgen_cb_drop = function(i) {
497529
return 0;
498530
};
499531

500-
__exports.__wbindgen_closure_wrapper452 = function(a, b, _ignored) {
532+
__exports.__wbindgen_closure_wrapper439 = function(a, b, _ignored) {
501533
const f = wasm.__wbg_function_table.get(4);
502534
const d = wasm.__wbg_function_table.get(5);
503535
const cb = function(arg0) {

examples/todomvc/pkg/todomvc_bg.wasm

54 KB
Binary file not shown.

examples/todomvc/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ enum Msg {
110110
EditKeyDown(usize, u32), // item position, keycode
111111
}
112112

113-
fn update(history: &History<Model, Msg>, msg: Msg, model: Model) -> Model {
113+
fn update(history: &mut History<Model, Msg>, msg: Msg, model: Model) -> Model {
114114
// We take a verbose immutable-design/functional approach in this example.
115115
// Alternatively, you could re-declare model as mutable at the top, and mutate
116116
// what we need in each match leg. See the Update section of the guide for details.
@@ -187,7 +187,7 @@ fn update(history: &History<Model, Msg>, msg: Msg, model: Model) -> Model {
187187
},
188188
Msg::EditSubmit(posit) => {
189189
if model.edit_text.is_empty() {
190-
update(Msg::Destroy(posit), model)
190+
update(history, Msg::Destroy(posit), model)
191191
} else {
192192
let mut todos = model.todos;
193193
let mut todo = todos.remove(posit);
@@ -206,7 +206,7 @@ fn update(history: &History<Model, Msg>, msg: Msg, model: Model) -> Model {
206206
.collect();
207207
Model {todos, edit_text: model.todos[posit].title.clone(), ..model}
208208
} else if code == ENTER_KEY {
209-
update(Msg::EditSubmit(posit), model)
209+
update(history, Msg::EditSubmit(posit), model)
210210
} else {model}
211211
},
212212
}

src/dom_types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl Attrs {
301301
}
302302

303303
/// Create an HTML-compatible string representation
304-
pub fn to_string(&self) -> String {
304+
pub fn as_str(&self) -> String {
305305
let mut result = String::new();
306306
for (key, val) in &self.vals {
307307
result += &format!(" {k}=\"{v}\"", k=key, v=val);
@@ -354,7 +354,7 @@ impl Style {
354354

355355
/// Output style as a string, as would be set in the DOM as the attribute value
356356
/// for 'style'. Eg: "display: flex; font-size: 1.5em"
357-
pub fn to_string(&self) -> String {
357+
pub fn as_str(&self) -> String {
358358
let mut result = String::new();
359359
if self.vals.keys().len() > 0 {
360360
for (key, val) in &self.vals {
@@ -631,8 +631,8 @@ impl<Ms: Clone + 'static> El<Ms> {
631631
fn _html(&self) -> String {
632632
let text = self.text.clone().unwrap_or_default();
633633

634-
let opening = String::from("<") + self.tag.as_str() + &self.attrs.to_string() +
635-
" style=\"" + &self.style.to_string() + ">\n";
634+
let opening = String::from("<") + self.tag.as_str() + &self.attrs.as_str() +
635+
" style=\"" + &self.style.as_str() + ">\n";
636636

637637
let inner = self.children.iter().fold(String::new(), |result, child| result + &child._html());
638638

src/websys_bridge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn make_websys_el<Ms: Clone>(el_vdom: &mut dom_types::El<Ms>, document: &web
4444
// Style is just an attribute in the actual Dom, but is handled specially in our vdom;
4545
// merge the different parts of style here.
4646
if el_vdom.style.vals.keys().len() > 0 {
47-
el_ws.set_attribute("style", &el_vdom.style.to_string()).expect("Problem setting style");
47+
el_ws.set_attribute("style", &el_vdom.style.as_str()).expect("Problem setting style");
4848
}
4949

5050
// We store text as Option<String>, but set_text_content uses Option<&str>.
@@ -128,7 +128,7 @@ pub fn patch_el_details<Ms: Clone>(old: &mut dom_types::El<Ms>, new: &mut dom_ty
128128
// Patch style.
129129
if old.style != new.style {
130130
// We can't patch each part of style; rewrite the whole attribute.
131-
old_el_ws.set_attribute("style", &new.style.to_string())
131+
old_el_ws.set_attribute("style", &new.style.as_str())
132132
.expect("Setting style");
133133
}
134134

0 commit comments

Comments
 (0)