Skip to content

Instantly share code, notes, and snippets.

@jwatte
Last active December 13, 2015 19:19

Revisions

  1. jwatte revised this gist Feb 15, 2013. 1 changed file with 35 additions and 15 deletions.
    50 changes: 35 additions & 15 deletions Single Reactive Property
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,56 @@
    public class DrawingFeature : Feature

    public class DrawingFeature : Feature {
    public ReactiveProperty<Drawing> Drawing = new ReactiveProperty<Drawing>(this.OnFeatureChanged);
    }

    // use: theDrawingFeature.Drawing.It = ...;
    // theDrawingFeature.Drawing.Change += new EventHandler( ... );


    public class ReactiveProperty<T>
    {
    private Drawing drawing_;
    public event EventHandler DrawingChanged;
    private bool inDrawingChanged_;
    protected void OnDrawingChanged()
    public ReactiveProperty(ParentChange del)
    {
    parent_ = del;
    }
    private ParentChange parent_;
    private T it_;
    public event EventHandler Changed;
    private bool inChanged_;
    protected void OnChanged()
    {
    if (!inDrawingChanged_)
    if (!inChanged_)
    {
    inDrawingChanged_ = true;
    inChanged_ = true;
    try
    {
    if (DrawingChanged != null)
    if (Changed != null)
    {
    DrawingChanged(this, EventArgs.Empty);
    Changed(this, EventArgs.Empty);
    }
    if (parent_)
    {
    parent_();
    }
    OnFeatureChanged();
    }
    finally
    {
    inDrawingChanged_ = false;
    inChanged_ = false;
    }
    }
    }
    public Drawing Drawing {
    public T It
    {
    get
    {
    return drawing_;
    return it_;
    }
    set
    {
    drawing_ = value;
    OnDrawingChanged();
    it_ = value;
    OnChanged();
    }
    }
    }

    public delegate void ParentChanged();
  2. jwatte created this gist Feb 15, 2013.
    36 changes: 36 additions & 0 deletions Single Reactive Property
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    public class DrawingFeature : Feature
    {
    private Drawing drawing_;
    public event EventHandler DrawingChanged;
    private bool inDrawingChanged_;
    protected void OnDrawingChanged()
    {
    if (!inDrawingChanged_)
    {
    inDrawingChanged_ = true;
    try
    {
    if (DrawingChanged != null)
    {
    DrawingChanged(this, EventArgs.Empty);
    }
    OnFeatureChanged();
    }
    finally
    {
    inDrawingChanged_ = false;
    }
    }
    }
    public Drawing Drawing {
    get
    {
    return drawing_;
    }
    set
    {
    drawing_ = value;
    OnDrawingChanged();
    }
    }
    }