Skip to content
Open
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
14 changes: 2 additions & 12 deletions src/FreshMvvm/FreshBasePageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

namespace FreshMvvm
{
public abstract class FreshBasePageModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

public abstract class FreshBasePageModel : FreshObservableObject
{
/// <summary>
/// This event is raise when a page is Popped, this might not be raise everytime a page is Popped.
/// Note* this might be raised multiple times.
Expand Down Expand Up @@ -55,14 +53,6 @@ public virtual void Init (object initData)
{
}

protected void RaisePropertyChanged ([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) {
handler (this, new PropertyChangedEventArgs (propertyName));
}
}

internal void WireEvents (Page page)
{
page.Appearing += ViewIsAppearing;
Expand Down
3 changes: 2 additions & 1 deletion src/FreshMvvm/FreshMvvm.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -31,6 +31,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Compile Include="FreshObservableObject.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FreshBasePageModel.cs" />
<Compile Include="FreshIOC.cs" />
Expand Down
57 changes: 57 additions & 0 deletions src/FreshMvvm/FreshObservableObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace FreshMvvm
{
/// <summary>
/// Observable object with INotifyPropertyChanged implemented
/// </summary>
public abstract class FreshObservableObject : INotifyPropertyChanged
{
/// <summary>
/// Occurs when property changed.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// Sets the property.
/// </summary>
/// <returns><c>true</c>, if property was set, <c>false</c> otherwise.</returns>
/// <param name="backingStore">Backing store.</param>
/// <param name="value">Value.</param>
/// <param name="propertyName">Property name.</param>
/// <param name="onChanged">On changed.</param>
/// <typeparam name="T">The 1st type parameter.</typeparam>
protected bool SetProperty<T>(
ref T backingStore, T value,
[CallerMemberName]string propertyName = "",
Action onChanged = null)
{
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;

backingStore = value;

if (onChanged != null)
onChanged.Invoke();

RaisePropertyChanged(propertyName);
return true;
}

/// <summary>
/// Raises the property changed event.
/// </summary>
/// <param name="propertyName">Property name.</param>
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}