ReedCopsey / Gjallarhorn.Bindable

Unidirectional binding library built on top of Gjallarhorn for WPF and Xamarin Forms
MIT License
27 stars 10 forks source link

ApplicationCore and INavigator dependency #12

Open FoggyFinder opened 6 years ago

FoggyFinder commented 6 years ago

For now ApplicationCore and INavigator have not explicit dependency. But constructor takes function navUpdate (from INavigator) as a parameter

type ApplicationCore<'Model,'Nav,'Message> (initialModel, navUpdate : (ApplicationCore<'Model,'Nav,'Message> -> 'Nav -> unit), update, binding)

as a result, the use of navigation is not immediately obvious

let navigator = Navigation.singlePage App MainWin Login updateNavigation
let app = Program.applicationCore navigator.Navigate
Framework.RunApplication (navigator, app)

Anyway, it looks to me like implicit dependency.

But what if a bond for these types will be strong? For example

type ApplicationCore<'Model,'Nav,'Message> (initialModel, nav:INavigator<'Model, 'Nav, 'Message>, update, binding) =             

    member this.Navigation (msg : 'Nav) = 
        async {
            do! Async.SwitchToContext syncContext
            nav.Navigate this msg
        } |> Async.Start

    member __.Navigator : INavigator<'Model, 'Nav, 'Message> = nav 

and INavigator<'Model, 'Nav, 'Message> =
        abstract member Run : ApplicationCore<'Model,'Nav,'Message> -> (System.Threading.SynchronizationContext -> ObservableBindingSource<'Message>) -> unit
        abstract member Navigate : ApplicationCore<'Model,'Nav,'Message> -> 'Nav -> unit

and with a bit change of RunApplication

[<AbstractClass;Sealed>]
type Framework =
    /// Run an application given an Application generator, Window generator, and other required information
    static member RunApplication<'Model,'Nav,'Message> (applicationInfo : Framework.ApplicationCore<'Model,'Nav,'Message>) =        
        Framework.Framework.runApplication (App.toApplicationSpecification applicationInfo.Navigator applicationInfo) 

then the example above could be rewritten as

Navigation.singlePage App MainWin Login updateNavigation  
|> Program.applicationCore
|> Framework.RunApplication

which is slightly easier to perceive.

So, it's just a thought about navigation system.