1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//! `SortAndBind` (`Cache/ObservableCacheEx.SortAndBind.cs`): the changes applied to a list at
//! their sorted positions, the sort being part of the binding.
//!
//! The target is any list of DynamicData ([`IList`](crate::list::IList)) that is a shared handle:
//! an [`ObservableCollectionExtended`](crate::binding::ObservableCollectionExtended) (whose
//! notifications are suspended around the changes, as upstream does), an
//! `ObservableCollection<T>`, or a shared `Rc<RefCell<Vec<T>>>` (a `List<T>`). The forms that
//! take an `IComparable<TObject>` item use [`Ord`].
macro_rules! sort_and_bind_methods {
() => {
/// Sorts the items by `comparer` into `target` (`SortAndBind(IList<TObject>,
/// IComparer<TObject>)`), with the options of `DynamicDataOptions.SortAndBind`.
fn sort_and_bind<L: crate::list::IList<T> + Clone + 'static>(
&self,
target: &L,
comparer: std::rc::Rc<dyn Fn(&T, &T) -> std::cmp::Ordering>,
) -> std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>
where
T: PartialEq,
{
crate::binding::sort_and_bind::sort_and_bind(self.change_sets(), comparer, crate::DynamicDataOptions::sort_and_bind(), target.clone())
}
/// [`sort_and_bind`](Self::sort_and_bind) with `options` (`SortAndBind(IList<TObject>,
/// IComparer<TObject>, SortAndBindOptions)`).
fn sort_and_bind_with(
&self,
target: &(impl crate::list::IList<T> + Clone + 'static),
comparer: std::rc::Rc<dyn Fn(&T, &T) -> std::cmp::Ordering>,
options: crate::binding::SortAndBindOptions,
) -> std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>
where
T: PartialEq,
{
crate::binding::sort_and_bind::sort_and_bind(self.change_sets(), comparer, options, target.clone())
}
/// Sorts the items in their natural order into `target` (`SortAndBind(IList<TObject>)`,
/// `Comparer<TObject>.Default`).
fn sort_and_bind_by_default(
&self,
target: &(impl crate::list::IList<T> + Clone + 'static),
) -> std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>
where
T: Ord,
{
self.sort_and_bind_with(target, std::rc::Rc::new(|a: &T, b: &T| a.cmp(b)), crate::DynamicDataOptions::sort_and_bind())
}
/// [`sort_and_bind_by_default`](Self::sort_and_bind_by_default) with `options`
/// (`SortAndBind(IList<TObject>, SortAndBindOptions)`).
fn sort_and_bind_by_default_with(
&self,
target: &(impl crate::list::IList<T> + Clone + 'static),
options: crate::binding::SortAndBindOptions,
) -> std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>
where
T: Ord,
{
self.sort_and_bind_with(target, std::rc::Rc::new(|a: &T, b: &T| a.cmp(b)), options)
}
/// Sorts the items into `target` by the latest comparer of `comparer_changed`, sorting
/// again at each one (`SortAndBind(IList<TObject>, IObservable<IComparer<TObject>>)`).
fn sort_and_bind_on_observable(
&self,
target: &(impl crate::list::IList<T> + Clone + 'static),
comparer_changed: std::rc::Rc<dyn ferroui_system::IObservable<std::rc::Rc<dyn Fn(&T, &T) -> std::cmp::Ordering>>>,
) -> std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>
where
T: PartialEq,
{
self.sort_and_bind_on_observable_with(target, comparer_changed, crate::DynamicDataOptions::sort_and_bind())
}
/// [`sort_and_bind_on_observable`](Self::sort_and_bind_on_observable) with `options`
/// (`SortAndBind(IList<TObject>, IObservable<IComparer<TObject>>, SortAndBindOptions)`).
fn sort_and_bind_on_observable_with(
&self,
target: &(impl crate::list::IList<T> + Clone + 'static),
comparer_changed: std::rc::Rc<dyn ferroui_system::IObservable<std::rc::Rc<dyn Fn(&T, &T) -> std::cmp::Ordering>>>,
options: crate::binding::SortAndBindOptions,
) -> std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>
where
T: PartialEq,
{
crate::binding::sort_and_bind::sort_and_bind_dynamic(self.change_sets(), comparer_changed, options, target.clone())
}
/// Sorts the items by `comparer` into a new collection, returned as a read-only view
/// (`SortAndBind(out ReadOnlyObservableCollection<TObject>, IComparer<TObject>)`).
fn sort_and_bind_read_only(
&self,
comparer: std::rc::Rc<dyn Fn(&T, &T) -> std::cmp::Ordering>,
) -> (std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>, crate::binding::ReadOnlyObservableCollection<T>)
where
T: PartialEq,
{
self.sort_and_bind_read_only_with(comparer, crate::DynamicDataOptions::sort_and_bind())
}
/// [`sort_and_bind_read_only`](Self::sort_and_bind_read_only) with `options`, whose
/// initial capacity sizes the collection (`SortAndBind(out
/// ReadOnlyObservableCollection<TObject>, IComparer<TObject>, SortAndBindOptions)`).
fn sort_and_bind_read_only_with(
&self,
comparer: std::rc::Rc<dyn Fn(&T, &T) -> std::cmp::Ordering>,
options: crate::binding::SortAndBindOptions,
) -> (std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>, crate::binding::ReadOnlyObservableCollection<T>)
where
T: PartialEq,
{
let (target, read_only) = crate::cache::internal::bind::new_read_only_target::<T>(options.initial_capacity);
(crate::binding::sort_and_bind::sort_and_bind(self.change_sets(), comparer, options, target), read_only)
}
/// Sorts the items in their natural order into a new collection, returned as a read-only
/// view (`SortAndBind(out ReadOnlyObservableCollection<TObject>)`).
fn sort_and_bind_read_only_by_default(
&self,
) -> (std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>, crate::binding::ReadOnlyObservableCollection<T>)
where
T: Ord,
{
self.sort_and_bind_read_only_with(std::rc::Rc::new(|a: &T, b: &T| a.cmp(b)), crate::DynamicDataOptions::sort_and_bind())
}
/// [`sort_and_bind_read_only_by_default`](Self::sort_and_bind_read_only_by_default) with
/// `options` (`SortAndBind(out ReadOnlyObservableCollection<TObject>, SortAndBindOptions)`).
fn sort_and_bind_read_only_by_default_with(
&self,
options: crate::binding::SortAndBindOptions,
) -> (std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>, crate::binding::ReadOnlyObservableCollection<T>)
where
T: Ord,
{
self.sort_and_bind_read_only_with(std::rc::Rc::new(|a: &T, b: &T| a.cmp(b)), options)
}
/// Sorts the items by the latest comparer of `comparer_changed` into a new collection,
/// returned as a read-only view (`SortAndBind(out ReadOnlyObservableCollection<TObject>,
/// IObservable<IComparer<TObject>>)`).
fn sort_and_bind_read_only_on_observable(
&self,
comparer_changed: std::rc::Rc<dyn ferroui_system::IObservable<std::rc::Rc<dyn Fn(&T, &T) -> std::cmp::Ordering>>>,
) -> (std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>, crate::binding::ReadOnlyObservableCollection<T>)
where
T: PartialEq,
{
self.sort_and_bind_read_only_on_observable_with(comparer_changed, crate::DynamicDataOptions::sort_and_bind())
}
/// [`sort_and_bind_read_only_on_observable`](Self::sort_and_bind_read_only_on_observable)
/// with `options` (`SortAndBind(out ReadOnlyObservableCollection<TObject>,
/// IObservable<IComparer<TObject>>, SortAndBindOptions)`).
fn sort_and_bind_read_only_on_observable_with(
&self,
comparer_changed: std::rc::Rc<dyn ferroui_system::IObservable<std::rc::Rc<dyn Fn(&T, &T) -> std::cmp::Ordering>>>,
options: crate::binding::SortAndBindOptions,
) -> (std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>, crate::binding::ReadOnlyObservableCollection<T>)
where
T: PartialEq,
{
let (target, read_only) = crate::cache::internal::bind::new_read_only_target::<T>(options.initial_capacity);
(crate::binding::sort_and_bind::sort_and_bind_dynamic(self.change_sets(), comparer_changed, options, target), read_only)
}
/// Binds the results of `SortAndPage` or `SortAndVirtualize` to `target_list`, sorted by
/// the comparer of their context, with the options of their context
/// (`Bind(IList<TObject>)` of `IChangeSet<TObject, TKey, PageContext<TObject>>` and of
/// `IChangeSet<TObject, TKey, VirtualContext<TObject>>`).
///
/// # Panics
/// When the source is not a result of `SortAndPage` or `SortAndVirtualize`.
fn bind_to_list(
&self,
target_list: &(impl crate::list::IList<T> + Clone + 'static),
) -> std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>
where
T: PartialEq,
Self: Sized + 'static,
{
crate::cache::internal::bind::expect_bind_context_stream(self, target_list.clone(), None)
}
/// [`bind_to_list`](Self::bind_to_list) with `options` (`Bind(IList<TObject>,
/// SortAndBindOptions)` of the paged and virtualised change sets).
///
/// # Panics
/// When the source is not a result of `SortAndPage` or `SortAndVirtualize`.
fn bind_to_list_with(
&self,
target_list: &(impl crate::list::IList<T> + Clone + 'static),
options: crate::binding::SortAndBindOptions,
) -> std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>
where
T: PartialEq,
Self: Sized + 'static,
{
crate::cache::internal::bind::expect_bind_context_stream(self, target_list.clone(), Some(options))
}
/// Binds the results of `SortAndPage` or `SortAndVirtualize` to a new collection, returned
/// as a read-only view (`Bind(out ReadOnlyObservableCollection<TObject>,
/// SortAndBindOptions)` of the paged and virtualised change sets). Their form without
/// options is [`bind_read_only`](Self::bind_read_only).
///
/// # Panics
/// When the source is not a result of `SortAndPage` or `SortAndVirtualize`.
fn bind_read_only_with_sort_and_bind_options(
&self,
options: crate::binding::SortAndBindOptions,
) -> (std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>, crate::binding::ReadOnlyObservableCollection<T>)
where
T: PartialEq,
Self: Sized + 'static,
{
let (target, read_only) = crate::cache::internal::bind::new_read_only_target::<T>(None);
(crate::cache::internal::bind::expect_bind_context_stream(self, target, Some(options)), read_only)
}
};
}
pub(crate) use sort_and_bind_methods;