FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    ferroui_reactiveui

    module · ferroui-reactiveui · v0.5.0

    module ferroui_reactiveui
    

    ferroui-reactiveui

    A port of ReactiveUI (https://github.com/reactiveui/ReactiveUI) to Rust, in the flavour that runs on System.Reactive (here ferroui-reactive), together with the run time of ReactiveUI.Binding: reactive objects, commands, the observation of properties and the bindings of view models and views for MVVM. It depends on nothing of the user interface of FerroUI; the integration with the framework (the scheduler of the dispatcher, the observation of the properties of controls, the views) builds on it.

    The modules follow the folders of ReactiveUI.Core and ReactiveUI.Shared, in snake case, and the run time of ReactiveUI.Binding is under binding. Everything public is re-exported at the root, as upstream puts it in the namespaces ReactiveUI and ReactiveUI.Binding:

    A view model holds a ReactiveObject and is shared as an Rc:

    use ferroui_reactiveui::{reactive_object, reactive_properties, IReactiveNotifyPropertyChanged, ReactiveObject};
    use ferroui_reactive::ObservableExt;
    use std::cell::Cell;
    use std::rc::Rc;
    
    reactive_properties! {
        #[derive(Default)]
        pub struct Counter {
            reactive: ReactiveObject,
            #[reactive]
            count: i32,
        }
    }
    reactive_object!(Counter);
    
    let counter = Rc::new(Counter::default());
    let changes = Rc::new(Cell::new(0));
    let seen = changes.clone();
    let _subscription = counter.changed().subscribe_next(move |_| seen.set(seen.get() + 1));
    counter.set_count(1);
    counter.set_count(1);
    assert_eq!(changes.get(), 1);
    

    Everything is single-threaded and reference counted, as the object model of FerroUI is (docs/porting/reactive.md, section 5.1). An exception of user code is a panic; where upstream catches one, the port catches the panic (PanicError).

    View source

    Contents

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.