Exemple #1
0
        /// <summary> This will observe a specific subpart of the state that should be shown in the target presenter, and it will automatically
        /// call the OnLoad method of the presenter when the target subpart of the state changes. This should be taken into account by
        /// the presenter that OnLoad will happen multiple times and can happen at any time. </summary>
        /// <typeparam name="Model">The part of the state that will be shown in the presenter</typeparam>
        /// <param name="store">The target store that will be observerd</param>
        /// <param name="getSubState"> Select the substate part that is relevant for the presenter and return it in the fuction</param>
        /// <returns> A task that contains the first user model change made by the target presenter, so this can be awaited for presenters that
        /// await a final save button click and are closed afterwards. If the task is awaited for a presenter that stays open and does not have
        /// a linear flow like a form that closes itself in the end then the task cant be properly used and should not be awaited!</returns>
        public static Task <Model> ListenToStoreUpdates <T, Model>(this Presenter <Model> self, IDataStore <T> store, Func <T, Model> getSubState)
        {
            TaskCompletionSource <Model> tcs = new TaskCompletionSource <Model>();

            store.AddAsyncStateChangeListener(getSubState, async(newValue) => {
                tcs.TrySetResult(await self.LoadModelIntoView(newValue));
            });
            return(tcs.Task);
        }
Exemple #2
0
 public static void ListenToStoreUpdates <T, S>(this Presenter <S> self, IDataStore <T> store, Func <T, S> getSubState)
 {
     store.AddAsyncStateChangeListener(getSubState, (newValue) => { return(self.LoadModelIntoView(newValue)); });
 }