Skip to main content

ferroui_reactiveui/
lib.rs

1//! ferroui-reactiveui
2//!
3//! A port of ReactiveUI (<https://github.com/reactiveui/ReactiveUI>) to Rust, in the flavour that
4//! runs on System.Reactive (here `ferroui-reactive`), together with the run time of
5//! ReactiveUI.Binding: reactive objects, commands, the observation of properties and the bindings
6//! of view models and views for MVVM. It depends on nothing of the user interface of FerroUI; the
7//! integration with the framework (the scheduler of the dispatcher, the observation of the
8//! properties of controls, the views) builds on it.
9//!
10//! The modules follow the folders of ReactiveUI.Core and ReactiveUI.Shared, in snake case, and the
11//! run time of ReactiveUI.Binding is under `binding`. Everything public is re-exported at the
12//! root, as upstream puts it in the namespaces `ReactiveUI` and `ReactiveUI.Binding`:
13//!
14//! - [`reactive_object`]: [`ReactiveObject`], the part of a view model that notifies the changes
15//!   of its properties ([`IReactiveObject`], [`IReactiveObjectExt`]), [`ReactiveRecord`], and the
16//!   macros [`reactive_object!`] and [`reactive_properties!`] that write a view model's traits and
17//!   properties.
18//! - [`interfaces`]: the change notifications ([`IReactiveNotifyPropertyChanged`],
19//!   [`ReactivePropertyChangedEventArgs`]) and [`IHandleObservableErrors`].
20//! - [`scheduler`]: [`ScheduledSubject`].
21//! - The root: [`RxSchedulers`], [`RxState`], [`RxCacheSize`] and [`UnhandledErrorException`].
22//!
23//! A view model holds a [`ReactiveObject`] and is shared as an `Rc`:
24//!
25//! ```
26//! use ferroui_reactiveui::{reactive_object, reactive_properties, IReactiveNotifyPropertyChanged, ReactiveObject};
27//! use ferroui_reactive::ObservableExt;
28//! use std::cell::Cell;
29//! use std::rc::Rc;
30//!
31//! reactive_properties! {
32//!     #[derive(Default)]
33//!     pub struct Counter {
34//!         reactive: ReactiveObject,
35//!         #[reactive]
36//!         count: i32,
37//!     }
38//! }
39//! reactive_object!(Counter);
40//!
41//! let counter = Rc::new(Counter::default());
42//! let changes = Rc::new(Cell::new(0));
43//! let seen = changes.clone();
44//! let _subscription = counter.changed().subscribe_next(move |_| seen.set(seen.get() + 1));
45//! counter.set_count(1);
46//! counter.set_count(1);
47//! assert_eq!(changes.get(), 1);
48//! ```
49//!
50//! Everything is single-threaded and reference counted, as the object model of FerroUI is
51//! (`docs/porting/reactive.md`, section 5.1). An exception of user code is a panic; where upstream
52//! catches one, the port catches the panic ([`PanicException`]).
53
54pub mod interfaces;
55pub(crate) mod internal;
56pub mod reactive_object;
57mod rx_cache_size;
58mod rx_schedulers;
59mod rx_state;
60pub mod scheduler;
61mod unhandled_error_exception;
62
63pub mod binding;
64pub mod mixins;
65pub(crate) mod primitives;
66pub mod reactive_command;
67
68pub use binding::bindings::*;
69pub use binding::builder::*;
70pub use binding::command_binding::*;
71pub use binding::interactions::*;
72pub use binding::interfaces::*;
73pub use binding::mixins::*;
74pub use binding::observable_for_property::*;
75pub use binding::observables::*;
76pub use interfaces::*;
77pub use mixins::*;
78pub use reactive_command::*;
79pub use internal::PanicException;
80pub use reactive_object::*;
81pub use rx_cache_size::RxCacheSize;
82pub use rx_schedulers::RxSchedulers;
83pub use rx_state::RxState;
84pub use scheduler::*;
85pub use unhandled_error_exception::UnhandledErrorException;
86
87/// What the macros of the crate expand to, so that a crate that uses them needs no other
88/// dependency.
89#[doc(hidden)]
90pub mod __private {
91    pub use ferroui_splat::IEnableLogger;
92    pub use ferroui_system::component_model::{property_name_of, INotifyPropertyChanged, INotifyPropertyChanging};
93    pub use ferroui_system::events::Event;
94    pub use ferroui_system::{IObservable, ObservableError};
95    pub use ferroui_system::prop;
96    pub use paste::paste;
97}
98pub use primitives::IThreadAffineSequencer;
99pub use binding::view::*;
100pub mod activation;
101pub mod routing;
102pub mod suspension;
103mod rx_suspension;
104pub use activation::*;
105pub use routing::*;
106pub use suspension::*;
107pub use rx_suspension::RxSuspension;
108pub mod builder;
109pub mod change_sets;
110pub mod comparers;
111pub mod platform;
112pub mod reactive_property;
113pub mod registration;
114pub use builder::*;
115pub use change_sets::*;
116pub use comparers::*;
117pub use reactive_property::*;
118pub use registration::*;