Skip to content

Instantly share code, notes, and snippets.

fn render_button() -> Node<Msg> {
let (count, count_access) = use_istate(|| 0);
button![
format!("Pressed {} times", count),
on_click(move |_| count_access.set(count + 1))
]
pub fn complex_form_test() -> Node<Msg> {
let (_form_state, ctl) = use_form_state_builder::<Msg>()
.on_blur(|form_state| {
log!("Outputing the form state on blur due to the #on_blur closure");
log!(form_state);
})
.build();
div![
div![
fn hook_style_input() -> Node<Msg> {
let (mut input_string, string_access) = use_state(|| "".to_string());
if input_string == "Seed" {
input_string = "is pretty cool!".to_string();
}
div![
"Try typing 'Seed'",
input![
attrs! {At::Type => "text", At::Value => input_string},
fn hook_style_button() -> Node<Msg> {
// Declare a new state variable which we'll call "count"
let (count, count_access) = use_state(|| 0);
div![
p![format!("You clicked {} times", count)],
button![
on_click( move |_| count_access.set(count + 1)),
format!("Click Me × {}", count)
]
]
pub fn view() -> Node<Msg> {
let graphql_query = "{countries {name currency emoji}}";
let graphql_url = "https://countries.trevorblades.com/";
let container_name = "countries";
// GraphQL List hook, manages fetching data and keeping list up to date.
let (list, graphql_control) =
use_graphql_list::<Country>(graphql_query, graphql_url, container_name);
div![
@rebo
rebo / graphql_list.rs
Last active November 20, 2019 07:13
GraphQL backed list
use super::{Model, Msg};
use enclose::enclose as e;
use seed::{prelude::*, *};
use seed_comp_helpers::graphql_list::use_graphql_list;
use seed_comp_helpers::on_click;
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
pub struct Country {
name: String,
@rebo
rebo / main.rs
Last active November 10, 2019 10:09
use slotmap::{new_key_type, SlotMap};
// Enables a slotmap to use a typed key unique to Unit.
new_key_type! {struct UnitKey;}
#[derive(Copy, Clone, Debug)]
struct Unit {
health: i32,
attack_strength: i32,
id: UnitKey, //enables unique identification of units for mutation by owning grid.
@rebo
rebo / fetch.rs
Last active November 6, 2019 02:32
#[derive(Clone, Debug, Deserialize)]
struct Todo {
userId: u32,
id: u32,
title: String,
completed: bool,
}
...
@rebo
rebo / shared.rs
Last active October 30, 2019 01:25
#[topo::nested]
fn simplified_two_way() -> Node<Msg> {
let (view1, view2) = spawn_views("".to_string(), first, second);
div![view1, view2]
}
fn first(shared: SharedAccess<String>) -> Node<Msg> {
div![
label!["First Child Component, this input will send to the second component"],
@rebo
rebo / two_way.rs
Last active October 29, 2019 23:05
Two way communication between components
#[topo::nested]
fn two_way_components_example() -> Node<Msg> {
// two way communication between two compoments
// we need an accessor that can hold two access states.
// after this is passed to peer compoments this is then updated with reference
// to all peers
let (_state, shared_channel_access): ((StateAccess<String>, StateAccess<String>), _) =
use_state(|| {
let id = topo::Id::current();