Last active
March 22, 2016 07:46
-
-
Save diegofrata/5468196 to your computer and use it in GitHub Desktop.
SheepAspect + F# + INotifyPropertyChanged = Joy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace FSharp.Windows | |
open System.ComponentModel | |
[<AbstractClass>] | |
type Model() = | |
let propertyChangedEvent = Event<_,_>() | |
interface INotifyPropertyChanged with | |
[<CLIEvent>] | |
member this.PropertyChanged = propertyChangedEvent.Publish | |
member internal this.TriggerPropertyChanged propertyName = | |
propertyChangedEvent.Trigger(this, PropertyChangedEventArgs propertyName) | |
namespace FSharp.Windows.Aspects | |
open SheepAspect.Runtime | |
open SheepAspect.Framework | |
[<Aspect>] | |
type public NotifyPropertyChangedAspect() = | |
[<SelectPropertyMethods("Setter && InType:AssignableToType:'FSharp.Windows.Model'")>] | |
member this.Setter() = () | |
[<Around("Setter")>] | |
member this.NotifyPropertyChanged (p : PropertySetJointPoint) = | |
(p.This :?> FSharp.Windows.Model).TriggerPropertyChanged p.Property.Name | |
namespace Global | |
open System | |
type MyModel () = | |
inherit FSharp.Windows.Model () | |
member val Name = "" with get, set | |
module Program = | |
[<EntryPoint>] | |
let main argv = | |
let model = MyModel() | |
do | |
(model :> System.ComponentModel.INotifyPropertyChanged).PropertyChanged.Add (fun x -> printf "Property %s notified!" x.PropertyName) | |
model.Name <- "Diego Frata" | |
Console.ReadLine () |> ignore | |
0 |
It's a great idea but I think NotifyPropertyChanged it's missing this:
p.Execute() |> ignore
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dmitry-a-morozov I think this approach, using SheepAspect, would improve much of the practices on your framework. In fact with this you don't need factories, proxies, etc.