/// <summary> /// The view sends messages using this method. This method is also used for messages originating from the world /// of effectful computations. In a way, this class also belongs to that world... /// </summary> /// <param name="message"></param> internal void SendMessage(Message message) { // Invoke the dispatching function with current model, current view model and the message. var newMandVm = Dispatching.dispatch(this.model, this.viewModel, message); // Remember new model and view model as current model and view model, respectively. Observe, that this // class doesn't care whether the model or view model actually changed. this.model = newMandVm.Item1; this.viewModel = newMandVm.Item2; // If the model requested an effectful computation, perform it and route the message back to this function, // such that it will be passed to the dispatcher function, exactly the same way as for messages coming from // the view. var effect = newMandVm.Item3; if (effect.IsEffect) { var e = effect as Effect <Message> .Effect; ExecuteEffect(e.Item, this.SendMessage); // executes asynchronously (AE) } // Send the updated view model to the view. Property (AE) is crucial, because the GUI will not be blocked // and the view can assume any intermediate state defined by the view model, until the computation (if any) // is done. The example in this demo is simulated verification of stamp rareness, where the view displays a // "working on it" feed-back. this.viewModelSubject.OnNext(this.viewModel); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> public DispatcherInvocationContext(Dispatching.Dispatcher dispatcher, Object handler, Object message) { _dispatcher = dispatcher; _handler = handler; _message = message; }