All Projects → futursolo → bounce

futursolo / bounce

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
The uncomplicated Yew State management library

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to bounce

fullstack-rust
Reference implementation of a full-stack Rust application
Stars: ✭ 39 (-9.3%)
Mutual labels:  wasm, yew
material-yew
Yew wrapper for Material Web Components
Stars: ✭ 116 (+169.77%)
Mutual labels:  wasm, yew
rocket-yew-starter-pack
Example boilerplate for websites in pure Rust
Stars: ✭ 77 (+79.07%)
Mutual labels:  wasm, yew
rust-electron-demo
rust electron demo using yew
Stars: ✭ 15 (-65.12%)
Mutual labels:  wasm, yew
ybc
A Yew component library based on the Bulma CSS framework.
Stars: ✭ 131 (+204.65%)
Mutual labels:  wasm, yew
facade
Facade Framework - autogenerated embedded live dashboards for Rust apps
Stars: ✭ 95 (+120.93%)
Mutual labels:  wasm, yew
wasi-worker
WASM / WASI interface for browser service workers
Stars: ✭ 31 (-27.91%)
Mutual labels:  wasm, yew
Yewdux
Redux-like state containers for Yew apps
Stars: ✭ 58 (+34.88%)
Mutual labels:  state-management, wasm
hash-wasm
Lightning fast hash functions using hand-tuned WebAssembly binaries
Stars: ✭ 382 (+788.37%)
Mutual labels:  wasm
ReduxSwift
Predictable state container for Swift too
Stars: ✭ 38 (-11.63%)
Mutual labels:  state-management
ReduRx
👌 A thin layer of a Redux-based state manager on top of RxDart
Stars: ✭ 41 (-4.65%)
Mutual labels:  state-management
glicol
(Audio) graph-oriented live coding language and music DSP library written in Rust
Stars: ✭ 853 (+1883.72%)
Mutual labels:  wasm
getx snippets extension
An extension to accelerate the process of developing applications with flutter, aimed at everyone using the GetX package.
Stars: ✭ 142 (+230.23%)
Mutual labels:  state-management
python-wasm
Build scripts and configuration for building CPython for Emscripten
Stars: ✭ 606 (+1309.3%)
Mutual labels:  wasm
restate
A redux fractal state library 🕷
Stars: ✭ 55 (+27.91%)
Mutual labels:  state-management
jedisdb
redis like key-value state management solution for React
Stars: ✭ 13 (-69.77%)
Mutual labels:  state-management
incubator-eventmesh
EventMesh is a dynamic event-driven application runtime used to decouple the application and backend middleware layer, which supports a wide range of use cases that encompass complex multi-cloud, widely distributed topologies using diverse technology stacks.
Stars: ✭ 939 (+2083.72%)
Mutual labels:  state-management
wasp
🐝 Wasp : Wasm programming (language)
Stars: ✭ 93 (+116.28%)
Mutual labels:  wasm
whatsup
Reactive framework, simple, fast, easy to use!
Stars: ✭ 115 (+167.44%)
Mutual labels:  state-management
emscripten-webxr
WebXR library for use with Emscripten.
Stars: ✭ 21 (-51.16%)
Mutual labels:  wasm

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! {
        <div>
            <input type="text" oninput={on_text_input} value={username.inner.to_string()} />
        </div>
    }
}

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! { <div>{"Hello, "}{&username.inner}</div> }
}

You can find the full example here.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].