Skip to content

Commit 339162c

Browse files
author
Todd Berman
committed
convert the rest
1 parent 93b6634 commit 339162c

File tree

6 files changed

+120
-846
lines changed

6 files changed

+120
-846
lines changed

ReactiveUI.Platforms/Cocoa/ReactiveCollectionViewCell.cs

Lines changed: 20 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace ReactiveUI.Cocoa
2020
{
21-
public abstract class ReactiveCollectionViewCell : UICollectionViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors
21+
public abstract class ReactiveCollectionViewCell : UICollectionViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension
2222
{
2323
public ReactiveCollectionViewCell(IntPtr handle) : base (handle) { setupRxObj(); }
2424
public ReactiveCollectionViewCell(NSObjectFlag t) : base (t) { setupRxObj(); }
@@ -29,53 +29,49 @@ public abstract class ReactiveCollectionViewCell : UICollectionViewCell, IReacti
2929
[field:IgnoreDataMember]
3030
public event PropertyChangingEventHandler PropertyChanging;
3131

32+
void IReactiveObjectExtension.RaisePropertyChanging(PropertyChangingEventArgs args) {
33+
var handler = PropertyChanging;
34+
if (handler != null) {
35+
handler(this, args);
36+
}
37+
}
38+
3239
[field:IgnoreDataMember]
3340
public event PropertyChangedEventHandler PropertyChanged;
3441

42+
void IReactiveObjectExtension.RaisePropertyChanged(PropertyChangedEventArgs args) {
43+
var handler = PropertyChanged;
44+
if (handler != null) {
45+
handler(this, args);
46+
}
47+
}
48+
3549
/// <summary>
3650
/// Represents an Observable that fires *before* a property is about to
3751
/// be changed.
3852
/// </summary>
3953
[IgnoreDataMember]
4054
public IObservable<IObservedChange<object, object>> Changing {
41-
get { return changingSubject; }
55+
get { return this.getChangingObservable(); }
4256
}
4357

4458
/// <summary>
4559
/// Represents an Observable that fires *after* a property has changed.
4660
/// </summary>
4761
[IgnoreDataMember]
4862
public IObservable<IObservedChange<object, object>> Changed {
49-
get { return changedSubject; }
63+
get { return this.getChangedObservable(); }
5064
}
5165

5266
[IgnoreDataMember]
53-
protected Lazy<PropertyInfo[]> allPublicProperties;
54-
55-
[IgnoreDataMember]
56-
Subject<IObservedChange<object, object>> changingSubject;
57-
58-
[IgnoreDataMember]
59-
Subject<IObservedChange<object, object>> changedSubject;
60-
61-
[IgnoreDataMember]
62-
long changeNotificationsSuppressed = 0;
63-
64-
[IgnoreDataMember]
65-
readonly ScheduledSubject<Exception> thrownExceptions = new ScheduledSubject<Exception>(Scheduler.Immediate, RxApp.DefaultExceptionHandler);
66-
67-
[IgnoreDataMember]
68-
public IObservable<Exception> ThrownExceptions { get { return thrownExceptions; } }
67+
public IObservable<Exception> ThrownExceptions { get { return this.getThrownExceptionsObservable(); } }
6968

7069
[OnDeserialized]
7170
void setupRxObj(StreamingContext sc) { setupRxObj(); }
7271

7372
void setupRxObj()
7473
{
75-
changingSubject = new Subject<IObservedChange<object, object>>();
76-
changedSubject = new Subject<IObservedChange<object, object>>();
77-
78-
allPublicProperties = new Lazy<PropertyInfo[]>(() => GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).ToArray());
74+
this.setupReactiveExtension();
7975
}
8076

8177
/// <summary>
@@ -87,123 +83,7 @@ void setupRxObj()
8783
/// notifications.</returns>
8884
public IDisposable SuppressChangeNotifications()
8985
{
90-
Interlocked.Increment(ref changeNotificationsSuppressed);
91-
return Disposable.Create(() => Interlocked.Decrement(ref changeNotificationsSuppressed));
92-
}
93-
94-
protected internal void raisePropertyChanging(string propertyName)
95-
{
96-
Contract.Requires(propertyName != null);
97-
98-
if (!areChangeNotificationsEnabled || changingSubject == null)
99-
return;
100-
101-
var handler = this.PropertyChanging;
102-
if (handler != null) {
103-
var e = new PropertyChangingEventArgs(propertyName);
104-
handler(this, e);
105-
}
106-
107-
notifyObservable(new ObservedChange<object, object>() {
108-
PropertyName = propertyName, Sender = this, Value = null
109-
}, changingSubject);
110-
}
111-
112-
protected internal void raisePropertyChanged(string propertyName)
113-
{
114-
Contract.Requires(propertyName != null);
115-
116-
this.Log().Debug("{0:X}.{1} changed", this.GetHashCode(), propertyName);
117-
118-
if (!areChangeNotificationsEnabled || changedSubject == null) {
119-
this.Log().Debug("Suppressed change");
120-
return;
121-
}
122-
123-
var handler = this.PropertyChanged;
124-
if (handler != null) {
125-
var e = new PropertyChangedEventArgs(propertyName);
126-
handler(this, e);
127-
}
128-
129-
notifyObservable(new ObservedChange<object, object>() {
130-
PropertyName = propertyName, Sender = this, Value = null
131-
}, changedSubject);
132-
}
133-
134-
protected bool areChangeNotificationsEnabled {
135-
get {
136-
return (Interlocked.Read(ref changeNotificationsSuppressed) == 0);
137-
}
138-
}
139-
140-
internal void notifyObservable<T>(T item, Subject<T> subject)
141-
{
142-
try {
143-
subject.OnNext(item);
144-
} catch (Exception ex) {
145-
this.Log().ErrorException("ReactiveObject Subscriber threw exception", ex);
146-
thrownExceptions.OnNext(ex);
147-
}
148-
}
149-
150-
/// <summary>
151-
/// RaiseAndSetIfChanged fully implements a Setter for a read-write
152-
/// property on a ReactiveObject, using CallerMemberName to raise the notification
153-
/// and the ref to the backing field to set the property.
154-
/// </summary>
155-
/// <typeparam name="TObj">The type of the This.</typeparam>
156-
/// <typeparam name="TRet">The type of the return value.</typeparam>
157-
/// <param name="This">The <see cref="ReactiveObject"/> raising the notification.</param>
158-
/// <param name="backingField">A Reference to the backing field for this
159-
/// property.</param>
160-
/// <param name="newValue">The new value.</param>
161-
/// <param name="propertyName">The name of the property, usually
162-
/// automatically provided through the CallerMemberName attribute.</param>
163-
/// <returns>The newly set value, normally discarded.</returns>
164-
public TRet RaiseAndSetIfChanged<TRet>(
165-
ref TRet backingField,
166-
TRet newValue,
167-
[CallerMemberName] string propertyName = null)
168-
{
169-
Contract.Requires(propertyName != null);
170-
171-
if (EqualityComparer<TRet>.Default.Equals(backingField, newValue)) {
172-
return newValue;
173-
}
174-
175-
raisePropertyChanging(propertyName);
176-
backingField = newValue;
177-
raisePropertyChanged(propertyName);
178-
return newValue;
179-
}
180-
181-
/// <summary>
182-
/// Use this method in your ReactiveObject classes when creating custom
183-
/// properties where raiseAndSetIfChanged doesn't suffice.
184-
/// </summary>
185-
/// <param name="This">The instance of ReactiveObject on which the property has changed.</param>
186-
/// <param name="propertyName">
187-
/// A string representing the name of the property that has been changed.
188-
/// Leave <c>null</c> to let the runtime set to caller member name.
189-
/// </param>
190-
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
191-
{
192-
raisePropertyChanged(propertyName);
193-
}
194-
195-
/// <summary>
196-
/// Use this method in your ReactiveObject classes when creating custom
197-
/// properties where raiseAndSetIfChanged doesn't suffice.
198-
/// </summary>
199-
/// <param name="This">The instance of ReactiveObject on which the property has changed.</param>
200-
/// <param name="propertyName">
201-
/// A string representing the name of the property that has been changed.
202-
/// Leave <c>null</c> to let the runtime set to caller member name.
203-
/// </param>
204-
public void RaisePropertyChanging([CallerMemberName] string propertyName = null)
205-
{
206-
raisePropertyChanging(propertyName);
86+
return this.suppressChangeNotifications();
20787
}
20888
}
20989
}

0 commit comments

Comments
 (0)