Refactoring Data Passing Methods in BuildIt.Lifecycle

In my earlier post, Passing Data Between States with BuildIt.Lifecycle, the state declarations for the primary application region started to look really messy. As promised I’ve tidied up the extension helper methods, making it much easier to define delegates that are invoked when changing to and from a state. The updated state declartion now looks like:

StateManager.GroupWithViewModels<AppStates>()
    .StateWithViewModel<AppStates, MainViewModel>(AppStates.Home)
        .OnCompleteWithData(MainCompletion.Settings,vm=>vm.HelloWithTime)
            .ChangeState(AppStates.Settings)
        .OnCompleteWithData< AppStates, MainViewModel,MainCompletion,string>(MainCompletion.About,null)
            .ChangeState(AppStates.About)
        .WhenChangedTo(async vm => await vm.LoadData())
    .EndState()
               
    .StateWithViewModel<AppStates, SettingsViewModel>(AppStates.Settings)
        .OnComplete(DefaultCompletion.Complete).ChangeToPreviousState()
        .WhenChangedToWithData<AppStates, SettingsViewModel, string>((vm, d) => vm.SettingsTitle = d)
    .EndState()
               
    .StateWithViewModel<AppStates, AboutViewModel>(AppStates.About)
        .WhenChangedToWithData<AppStates, AboutViewModel, string>((vm, d) => vm.AboutTitle = d)
    .EndState();

Note that if you’re attempting to use these updates they haven’t yet made their way into the NuGet packages. I’ll endeavour to update these packages later this week. In the meantime I’d recommend downloading the source from the BuildIt repository on GitHub.

Leave a comment