Updated example code and README to use latest syntax for data binding

This commit is contained in:
ekanna 2023-01-17 12:08:44 +05:30
parent 27ec506fd5
commit ce0910caca
4 changed files with 5 additions and 5 deletions

View File

@ -29,7 +29,7 @@ pub fn SimpleCounter(cx: Scope, initial_value: i32) -> impl IntoView {
<div> <div>
<button on:click=clear>"Clear"</button> <button on:click=clear>"Clear"</button>
<button on:click=decrement>"-1"</button> <button on:click=decrement>"-1"</button>
<span>"Value: " {move || value().to_string()} "!"</span> <span>"Value: " {value} "!"</span>
<button on:click=increment>"+1"</button> <button on:click=increment>"+1"</button>
</div> </div>
} }

View File

@ -17,7 +17,7 @@ pub fn SimpleCounter(
<div> <div>
<button on:click=move |_| set_value(0)>"Clear"</button> <button on:click=move |_| set_value(0)>"Clear"</button>
<button on:click=move |_| set_value.update(|value| *value -= step)>"-1"</button> <button on:click=move |_| set_value.update(|value| *value -= step)>"-1"</button>
<span>"Value: " {move || value().to_string()} "!"</span> <span>"Value: " {value} "!"</span>
<button on:click=move |_| set_value.update(|value| *value += step)>"+1"</button> <button on:click=move |_| set_value.update(|value| *value += step)>"+1"</button>
</div> </div>
} }

View File

@ -116,7 +116,7 @@ pub fn Counter(cx: Scope) -> impl IntoView {
<div> <div>
<button on:click=move |_| clear.dispatch(())>"Clear"</button> <button on:click=move |_| clear.dispatch(())>"Clear"</button>
<button on:click=move |_| dec.dispatch(())>"-1"</button> <button on:click=move |_| dec.dispatch(())>"-1"</button>
<span>"Value: " {move || value().to_string()} "!"</span> <span>"Value: " {value} "!"</span>
<button on:click=move |_| inc.dispatch(())>"+1"</button> <button on:click=move |_| inc.dispatch(())>"+1"</button>
</div> </div>
{move || error_msg().map(|msg| view! { cx, <p>"Error: " {msg.to_string()}</p>})} {move || error_msg().map(|msg| view! { cx, <p>"Error: " {msg.to_string()}</p>})}

View File

@ -97,10 +97,10 @@ fn Counter(
<li> <li>
<button on:click=move |_| set_value.update(move |value| *value -= 1)>"-1"</button> <button on:click=move |_| set_value.update(move |value| *value -= 1)>"-1"</button>
<input type="text" <input type="text"
prop:value={move || value().to_string()} prop:value={value}
on:input=input on:input=input
/> />
<span>{move || value().to_string()}</span> <span>{value}</span>
<button on:click=move |_| set_value.update(move |value| *value += 1)>"+1"</button> <button on:click=move |_| set_value.update(move |value| *value += 1)>"+1"</button>
<button on:click=move |_| set_counters.update(move |counters| counters.retain(|(counter_id, _)| counter_id != &id))>"x"</button> <button on:click=move |_| set_counters.update(move |counters| counters.retain(|(counter_id, _)| counter_id != &id))>"x"</button>
</li> </li>