2020-01-06 04:49:11 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using ReactiveUI;
|
2019-10-11 22:18:51 +00:00
|
|
|
|
using System;
|
2019-10-09 22:59:58 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-10-11 22:18:51 +00:00
|
|
|
|
using System.Reactive.Disposables;
|
2019-10-09 22:59:58 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
2019-10-16 03:10:34 +00:00
|
|
|
|
namespace Wabbajack.Lib
|
2019-10-09 22:59:58 +00:00
|
|
|
|
{
|
2019-10-11 22:18:51 +00:00
|
|
|
|
public class ViewModel : ReactiveObject, IDisposable
|
2019-10-09 22:59:58 +00:00
|
|
|
|
{
|
2019-11-21 15:51:57 +00:00
|
|
|
|
private readonly Lazy<CompositeDisposable> _compositeDisposable = new Lazy<CompositeDisposable>();
|
2020-01-06 04:49:11 +00:00
|
|
|
|
[JsonIgnore]
|
2019-11-21 15:51:57 +00:00
|
|
|
|
public CompositeDisposable CompositeDisposable => _compositeDisposable.Value;
|
2019-10-09 22:59:58 +00:00
|
|
|
|
|
2019-10-11 22:18:51 +00:00
|
|
|
|
public virtual void Dispose()
|
2019-10-09 22:59:58 +00:00
|
|
|
|
{
|
2019-11-21 15:51:57 +00:00
|
|
|
|
if (_compositeDisposable.IsValueCreated)
|
2019-10-11 22:18:51 +00:00
|
|
|
|
{
|
2019-11-21 15:51:57 +00:00
|
|
|
|
_compositeDisposable.Value.Dispose();
|
2019-10-11 22:18:51 +00:00
|
|
|
|
}
|
2019-10-09 22:59:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void RaiseAndSetIfChanged<T>(
|
|
|
|
|
ref T item,
|
|
|
|
|
T newItem,
|
|
|
|
|
[CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
if (EqualityComparer<T>.Default.Equals(item, newItem)) return;
|
|
|
|
|
item = newItem;
|
|
|
|
|
this.RaisePropertyChanged(propertyName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|