Skip to content

Commit

Permalink
RE.Avalonia v1.2.1 - new CompositionRoot methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMarr committed Feb 5, 2024
1 parent 8351a4c commit fb29ace
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/ReactiveElmish.Avalonia/CompositionRoot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ type CompositionRoot() as this =
| None ->
failwithf $"No view registered for VM type {vmType.FullName}"

///Check to see if a view has been registered for the given view model
/// Check to see if a view has been registered for the given view model.
member this.HasViewFor(vm: 'ViewModel & #ReactiveElmishViewModel) =
let vmType = vm.GetType()
viewRegistry.Value |> Map.tryFind(VM.Key vmType) |> Option.isSome

///Gets or creates a view for a given view model instance and binds it
/// Gets or creates a view for a given view model instance and binds it.
member this.GetViewFor(vm: 'ViewModel & #ReactiveElmishViewModel) =
let vmType = vm.GetType()
match viewRegistry.Value |> Map.tryFind (VM.Key vmType) with
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveElmish.Avalonia/ReactiveElmish.Avalonia.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/JordanMarr/ReactiveElmish.Avalonia</PackageProjectUrl>
<PackageTags>Avalonia F# fsharp Elmish Elm</PackageTags>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<!--Turn on warnings for unused values (arguments and let bindings) -->
<OtherFlags>$(OtherFlags) --warnon:1182</OtherFlags>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
Expand Down
2 changes: 1 addition & 1 deletion src/Samples/AvaloniaExample/App.axaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type App() =
override this.OnFrameworkInitializationCompleted() =
match this.ApplicationLifetime with
| :? IClassicDesktopStyleApplicationLifetime as desktop ->
let appRoot = Root.Current
let appRoot = AppCompositionRoot.Instance
desktop.MainWindow <- appRoot.GetView<ViewModels.MainViewModel>() :?> Window
| _ ->
// leave this here for design view re-renders
Expand Down
6 changes: 3 additions & 3 deletions src/Samples/AvaloniaExample/AppCompositionRoot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type AppCompositionRoot() =
VM.Key<ChartViewModel>(), View.Singleton<ChartView>()
VM.Key<FilePickerViewModel>(), View.Singleton<FilePickerView>()
]

static member private instanceLazy = lazy AppCompositionRoot()
static member Instance = AppCompositionRoot.instanceLazy.Value

module Root =
let private current = lazy AppCompositionRoot()
let public Current = current.Value

4 changes: 2 additions & 2 deletions src/Samples/AvaloniaExample/ViewLocator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ViewLocator() =

member this.Build(data) =
match data with
| :? ReactiveElmishViewModel as reactiveViewModel -> Root.Current.GetViewFor(reactiveViewModel)
| :? ReactiveElmishViewModel as reactiveViewModel -> AppCompositionRoot.Instance.GetViewFor(reactiveViewModel)
| _ ->
let t = data.GetType()
let viewName = t.FullName.Replace("ViewModels", "Views").Replace("ViewModel", "View")
Expand All @@ -34,7 +34,7 @@ type ViewLocator() =

member this.Match(data) =
match data with
| :? ReactiveElmishViewModel as reactiveViewModel -> Root.Current.HasViewFor(reactiveViewModel)
| :? ReactiveElmishViewModel as vm -> AppCompositionRoot.Instance.HasViewFor(vm)
| :? ReactiveUI.ReactiveObject -> true
| _ -> false

0 comments on commit fb29ace

Please sign in to comment.