MCPcopy Index your code
hub / github.com/bounce-rs/bounce

github.com/bounce-rs/bounce @v0.9.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.9.0 ↗ · + Follow
416 symbols 676 edges 50 files 46 documented · 11% updated 3mo agov0.9.0 · 2023-10-15★ 9911 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Bounce

Run Tests & Publishing crates.io docs.rs

The uncomplicated state management library for Yew.

Bounce is inspired by Redux and Recoil.

Rationale

Yew state management solutions that are currently available all have some (or all) of the following limitations:

  • Too much boilerplate.

Users either have to manually control whether to notify subscribers or have to manually define contexts.

  • State change notifies all.

State changes will notify all subscribers.

  • Needless clones.

A clone of the state will be produced for all subscribers whenever there's a change.

Bounce wants to be a state management library that:

  • Has minimal boilerplate.

Changes are automatically detected via PartialEq.

  • Only notifies relevant subscribers.

When a state changes, only hooks that subscribe to that state will be notified.

  • Reduces Cloning.

States are Rc'ed.

Example

For bounce states to function, a <BounceRoot /> must be registered.

#[function_component(App)]
fn app() -> Html {
    html! {
        <BounceRoot>
            {children}
        </BounceRoot>
    }
}

A simple state is called an Atom.

You can derive Atom for any struct that implements PartialEq and Default.

#[derive(PartialEq, Atom)]
struct Username {
    inner: String,
}

impl Default for Username {
    fn default() -> Self {
        Self {
            inner: "Jane Doe".into(),
        }
    }
}

You can then use it with the use_atom hook.

When an Atom is first used, it will be initialised with its Default value.

#[function_component(Setter)]
fn setter() -> Html {
    let username = use_atom::<Username>();

    let on_text_input = {
        let username = username.clone();

        Callback::from(move |e: InputEvent| {
            let input: HtmlInputElement = e.target_unchecked_into();

            username.set(Username { inner: input.value().into() });
        })
    };

    html! {



            <input type="text" oninput={on_text_input} value={username.inner.to_string()} />



    }
}

If you wish to create a read-only (or set-only) handle, you can use use_atom_value (or use_atom_setter).

#[function_component(Reader)]
fn reader() -> Html {
    let username = use_atom_value::<Username>();

    html! { 

{"Hello, "}{&username.inner}

 }
}

You can find the full example here.

License

Bounce is dual licensed under the MIT license and the Apache License (Version 2.0).

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 169
Method 141
Class 74
Enum 20
Interface 12

Languages

Rust100%

Modules by API surface

crates/bounce/src/states/slice.rs21 symbols
examples/notion/src/main.rs20 symbols
crates/bounce/src/states/atom.rs20 symbols
examples/partial-render/src/main.rs18 symbols
crates/bounce/src/root_state.rs18 symbols
examples/queries-mutations/src/main.rs16 symbols
crates/bounce/src/states/input_selector.rs15 symbols
examples/divisibility/src/main.rs14 symbols
crates/bounce/src/query/query_states.rs14 symbols
crates/bounce/src/query/mutation_states.rs14 symbols
examples/title/src/main.rs12 symbols
examples/simple/src/main.rs12 symbols

For agents

$ claude mcp add bounce \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page