Skip to content

Disable WeakEventManager for WPF #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ReactiveUI.Tests/Android/PropertyBindingTestViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Android.App;
using Android.Widget;
using Android.Content;
using ReactiveUI.Android;
using Xunit;

namespace ReactiveUI.Tests
Expand Down
36 changes: 26 additions & 10 deletions ReactiveUI/ReactiveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,31 @@ public static ReactiveCommand<object> CreateCombined(params IReactiveCommand[] c
/// </summary>
public class ReactiveCommand<T> : IReactiveCommand<T>, IReactiveCommand
{
#if NET_45
public event EventHandler CanExecuteChanged;

protected virtual void raiseCanExecuteChanged(EventArgs args)
{
var handler = this.CanExecuteChanged;
if (handler != null) {
handler(this, args);
}
}
#else
public event EventHandler CanExecuteChanged
{
add {
if (canExecuteDisp == null) canExecuteDisp = canExecute.Connect();
CanExecuteChangedEventManager.AddHandler(this, value);
}
remove { CanExecuteChangedEventManager.RemoveHandler(this, value); }
}

protected virtual void raiseCanExecuteChanged(EventArgs args)
{
CanExecuteChangedEventManager.DeliverEvent(this, args);
}
#endif
readonly Subject<T> executeResults = new Subject<T>();
readonly Subject<bool> isExecuting = new Subject<bool>();
readonly Func<object, IObservable<T>> executeAsync;
Expand Down Expand Up @@ -310,7 +335,7 @@ public ReactiveCommand(IObservable<bool> canExecute, Func<object, IObservable<T>
canExecuteLatest = x;

if (fireCanExecuteChanged) {
CanExecuteChangedEventManager.DeliverEvent(this, EventArgs.Empty);
this.raiseCanExecuteChanged(EventArgs.Empty);
}
})
.Publish();
Expand Down Expand Up @@ -419,15 +444,6 @@ public bool CanExecute(object parameter)
return canExecuteLatest;
}

public event EventHandler CanExecuteChanged
{
add {
if (canExecuteDisp == null) canExecuteDisp = canExecute.Connect();
CanExecuteChangedEventManager.AddHandler(this, value);
}
remove { CanExecuteChangedEventManager.RemoveHandler(this, value); }
}

public void Execute(object parameter)
{
ExecuteAsync(parameter).Subscribe();
Expand Down
62 changes: 52 additions & 10 deletions ReactiveUI/ReactiveList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,47 @@ namespace ReactiveUI
[DebuggerTypeProxy(typeof(CollectionDebugView<>))]
public class ReactiveList<T> : IReactiveList<T>, IReadOnlyReactiveList<T>, IList
{
#if NET_45
public event NotifyCollectionChangedEventHandler CollectionChanging;

protected virtual void raiseCollectionChanging(NotifyCollectionChangedEventArgs args)
{
var handler = this.CollectionChanging;
if (handler != null) {
handler(this, args);
}
}

public event NotifyCollectionChangedEventHandler CollectionChanged;

protected virtual void raiseCollectionChanged(NotifyCollectionChangedEventArgs args)
{
var handler = this.CollectionChanged;
if (handler != null) {
handler(this, args);
}
}

public event PropertyChangingEventHandler PropertyChanging;

void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args)
{
var handler = this.PropertyChanging;
if (handler != null) {
handler(this, args);
}
}

public event PropertyChangedEventHandler PropertyChanged;

void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args)
{
var handler = this.PropertyChanged;
if (handler != null) {
handler(this, args);
}
}
#else
public event NotifyCollectionChangedEventHandler CollectionChanging {
add { CollectionChangingEventManager.AddHandler(this, value); }
remove { CollectionChangingEventManager.RemoveHandler(this, value); }
Expand All @@ -32,6 +73,16 @@ public event NotifyCollectionChangedEventHandler CollectionChanged {
add { CollectionChangedEventManager.AddHandler(this, value); }
remove { CollectionChangedEventManager.RemoveHandler(this, value); }
}

protected virtual void raiseCollectionChanging(NotifyCollectionChangedEventArgs e)
{
CollectionChangingEventManager.DeliverEvent(this, e);
}

protected virtual void raiseCollectionChanged(NotifyCollectionChangedEventArgs e)
{
CollectionChangedEventManager.DeliverEvent(this, e);
}

public event PropertyChangingEventHandler PropertyChanging
{
Expand All @@ -53,6 +104,7 @@ void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args)
{
PropertyChangedEventManager.DeliverEvent(this, args);
}
#endif

[IgnoreDataMember] Subject<NotifyCollectionChangedEventArgs> _changing;
[IgnoreDataMember] Subject<NotifyCollectionChangedEventArgs> _changed;
Expand Down Expand Up @@ -634,16 +686,6 @@ static IObservable<TObs> refcountSubscribers<TObs>(IObservable<TObs> input, Acti
});
}

protected virtual void raiseCollectionChanging(NotifyCollectionChangedEventArgs e)
{
CollectionChangingEventManager.DeliverEvent(this, e);
}

protected virtual void raiseCollectionChanged(NotifyCollectionChangedEventArgs e)
{
CollectionChangedEventManager.DeliverEvent(this, e);
}

#region Super Boring IList crap

// The BinarySearch methods aren't technically on IList<T>, they're implemented straight on List<T>
Expand Down
22 changes: 22 additions & 0 deletions ReactiveUI/ReactiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ namespace ReactiveUI
[DataContract]
public class ReactiveObject : IReactiveNotifyPropertyChanged<ReactiveObject>, IHandleObservableErrors, IReactiveObject
{
#if NET_45
public event PropertyChangingEventHandler PropertyChanging;

void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args)
{
var handler = this.PropertyChanging;
if(handler != null) {
handler(this, args);
}
}

public event PropertyChangedEventHandler PropertyChanged;

void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args)
{
var handler = this.PropertyChanged;
if (handler != null) {
handler(this, args);
}
}
#else
public event PropertyChangingEventHandler PropertyChanging {
add { PropertyChangingEventManager.AddHandler(this, value); }
remove { PropertyChangingEventManager.RemoveHandler(this, value); }
Expand All @@ -43,6 +64,7 @@ void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args)
{
PropertyChangedEventManager.DeliverEvent(this, args);
}
#endif

/// <summary>
/// Represents an Observable that fires *before* a property is about to
Expand Down
12 changes: 7 additions & 5 deletions ReactiveUI/WeakEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@

namespace ReactiveUI
{
public class CanExecuteChangedEventManager : WeakEventManager<ICommand, EventHandler, EventArgs>
#if !NET_45
internal class CanExecuteChangedEventManager : WeakEventManager<ICommand, EventHandler, EventArgs>
{
}

public class PropertyChangingEventManager : WeakEventManager<INotifyPropertyChanging, PropertyChangingEventHandler, PropertyChangingEventArgs>
internal class PropertyChangingEventManager : WeakEventManager<INotifyPropertyChanging, PropertyChangingEventHandler, PropertyChangingEventArgs>
{
}

public class PropertyChangedEventManager : WeakEventManager<INotifyPropertyChanged, PropertyChangedEventHandler, PropertyChangedEventArgs>
internal class PropertyChangedEventManager : WeakEventManager<INotifyPropertyChanged, PropertyChangedEventHandler, PropertyChangedEventArgs>
{
}

public class CollectionChangingEventManager : WeakEventManager<INotifyCollectionChanging, NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>
internal class CollectionChangingEventManager : WeakEventManager<INotifyCollectionChanging, NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>
{
}

public class CollectionChangedEventManager : WeakEventManager<INotifyCollectionChanged, NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>
internal class CollectionChangedEventManager : WeakEventManager<INotifyCollectionChanged, NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>
{
}
#endif

/// <summary>
/// WeakEventManager base class. Inspired by the WPF WeakEventManager class and the code in
Expand Down