Skip to main content

ferroui_dynamic_data/
dynamic_data_options.rs

1//! `DynamicDataOptions` (`DynamicDataOptions.cs`): the defaults of the options of the binding
2//! operators, which an application may change.
3//!
4//! Deviation (DEVIATIONS.md, DynamicData): upstream's static properties are global; the port's are
5//! per thread, as its observables are (docs/porting/reactive.md, section 5.1).
6
7use crate::binding::{BindingOptions, SortAndBindOptions};
8use std::cell::{Cell, RefCell};
9
10ferroui_system::ferro_thread_local! {
11    static BINDING: Cell<BindingOptions> = Cell::new(BindingOptions::new(BindingOptions::DEFAULT_RESET_THRESHOLD));
12    static SORT_AND_BIND: RefCell<SortAndBindOptions> = RefCell::new(SortAndBindOptions::default());
13}
14
15/// The defaults of the options of the binding operators (`DynamicDataOptions`).
16pub struct DynamicDataOptions;
17
18impl DynamicDataOptions {
19    /// The options of `Bind` (`Binding`).
20    pub fn binding() -> BindingOptions {
21        BINDING.with(Cell::get)
22    }
23
24    /// Sets the options of `Bind` (`Binding { set; }`).
25    pub fn set_binding(options: BindingOptions) {
26        BINDING.with(|binding| binding.set(options));
27    }
28
29    /// The options of `SortAndBind` (`SortAndBind`).
30    pub fn sort_and_bind() -> SortAndBindOptions {
31        SORT_AND_BIND.with(|options| options.borrow().clone())
32    }
33
34    /// Sets the options of `SortAndBind` (`SortAndBind { set; }`).
35    pub fn set_sort_and_bind(options: SortAndBindOptions) {
36        SORT_AND_BIND.with(|current| *current.borrow_mut() = options);
37    }
38}