Skip to content

Commit

Permalink
Simplify change status handling
Browse files Browse the repository at this point in the history
References #21
  • Loading branch information
andreashuber-lawo committed Apr 26, 2016
1 parent c8a723e commit e262531
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
22 changes: 6 additions & 16 deletions Lawo.EmberPlusSharp/Model/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,8 @@ public string Description
/// <inheritdoc/>
public bool IsOnline
{
get
{
return this.isOnline;
}

internal set
{
var oldValue = this.RetrieveDetails;

if (this.SetValue(ref this.isOnline, value))
{
this.AdaptRetrieveDetailsChangeStatus(oldValue);
}
}
get { return this.isOnline; }
internal set { this.SetRetrieveDetailsChangeStatus(() => this.SetValue(ref this.isOnline, value)); }
}

/// <inheritdoc/>
Expand Down Expand Up @@ -141,9 +129,11 @@ internal virtual bool RetrieveDetails

internal RetrieveDetailsChangeStatus RetrieveDetailsChangeStatus { get; set; }

internal void AdaptRetrieveDetailsChangeStatus(bool oldValue)
internal void SetRetrieveDetailsChangeStatus(Func<bool> setValue)
{
if (this.RetrieveDetails != oldValue)
var oldValue = this.RetrieveDetails;

if (setValue() && (this.RetrieveDetails != oldValue))
{
// We're deliberately not simply setting this to Changed here, because we want to correctly handle
// the case when IsOnline is changed twice without being observed between the changes.
Expand Down
4 changes: 1 addition & 3 deletions Lawo.EmberPlusSharp/Model/NodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public ChildrenRetrievalPolicy ChildrenRetrievalPolicy
"value");
}

var oldValue = this.RetrieveDetails;
this.SetValue(ref this.childrenRetrievalPolicy, value);
this.AdaptRetrieveDetailsChangeStatus(oldValue);
this.SetRetrieveDetailsChangeStatus(() => this.SetValue(ref this.childrenRetrievalPolicy, value));
}
}
}
Expand Down

0 comments on commit e262531

Please sign in to comment.