Skip to content

Commit

Permalink
Simplified view model base.
Browse files Browse the repository at this point in the history
  • Loading branch information
benquarmby committed Aug 7, 2016
1 parent bf090d3 commit 5ba18b8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
3 changes: 2 additions & 1 deletion source/JSLintNet/UI/Settings/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ internal partial class SettingsViewModel : ViewModelBase
{
private static readonly Regex SeparatorPattern = new Regex(@"[\s,;'""]+", RegexOptions.Compiled);

public SettingsViewModel(JSLintNetSettings model)
public SettingsViewModel(IView view, JSLintNetSettings model)
: base(view)
{
this.Model = model;

Expand Down
10 changes: 3 additions & 7 deletions source/JSLintNet/UI/ViewFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ internal class ViewFactory : IViewFactory
{
public IView CreateSettings(JSLintNetSettings settings)
{
var viewModel = new SettingsViewModel(settings);
var view = new SettingsView()
{
DataContext = viewModel
};

viewModel.View = view;
var view = new SettingsView();
var viewModel = new SettingsViewModel(view, settings);
view.DataContext = viewModel;

return view;
}
Expand Down
21 changes: 6 additions & 15 deletions source/JSLintNet/UI/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
using System.ComponentModel;
using System.Linq.Expressions;

internal abstract class ViewModelBase : INotifyPropertyChanged, IDisposable
internal abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

public IView View { get; set; }

public void Dispose()
public ViewModelBase(IView view)
{
this.Dispose(true);
this.View = view;
}

protected virtual void Dispose(bool managed)
{
}
public event PropertyChangedEventHandler PropertyChanged;

protected IView View { get; private set; }

protected virtual void RaisePropertyChanged(string propertyName)
{
Expand All @@ -43,11 +39,6 @@ protected virtual void RaisePropertyChanged<T>(Expression<Func<T>> expression)
this.RaisePropertyChanged(memberExpression.Member.Name);
}

protected virtual void HandleAndClose(EventHandler handler)
{
this.HandleAndClose(handler, null);
}

protected virtual void HandleAndClose(EventHandler handler, bool? result)
{
if (handler != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using JSLintNet.QualityTools;
using JSLintNet.QualityTools.Expectations;
using JSLintNet.Settings;
using JSLintNet.UI;
using JSLintNet.UI.Settings;
using Moq;
using Xunit;

public class SettingsViewModelUnit
Expand Down Expand Up @@ -104,13 +106,16 @@ public GlobalVariablesTestable()
settings.Options = new JSLintOptions();

this.Model = settings;
this.ViewMock = new Mock<IView>();
}

public JSLintNetSettings Model { get; set; }

public Mock<IView> ViewMock { get; set; }

protected override SettingsViewModel Resolve()
{
return new SettingsViewModel(this.Model);
return new SettingsViewModel(this.ViewMock.Object, this.Model);
}
}
}
Expand Down

0 comments on commit 5ba18b8

Please sign in to comment.