Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ListenIncludeLatest method to MessageBus to receive last sended…

… message.
  • Loading branch information...
commit 2746e568435f84547e558c695da026ddd6d35b6c 1 parent dc29cfc
@jlaanstra jlaanstra authored
Showing with 31 additions and 1 deletion.
  1. +13 −0 ReactiveUI/Interfaces.cs
  2. +18 −1 ReactiveUI/MessageBus.cs
View
13 ReactiveUI/Interfaces.cs
@@ -295,6 +295,19 @@ public interface IMessageBus : IEnableLogger
IObservable<T> Listen<T>(string contract = null);
/// <summary>
+ /// ListenIncludeLatest provides an Observable that will fire whenever a Message is
+ /// provided for this object via RegisterMessageSource or SendMessage and fire the
+ /// last provided Message immediately if applicable, or null.
+ /// </summary>
+ /// <typeparam name="T">The type of the message to listen to.</typeparam>
+ /// <param name="contract">A unique string to distinguish messages with
+ /// identical types (i.e. "MyCoolViewModel") - if the message type is
+ /// only used for one purpose, leave this as null.</param>
+ /// <returns>An Observable representing the notifications posted to the
+ /// message bus.</returns>
+ IObservable<T> ListenIncludeLatest<T>(string contract = null);
+
+ /// <summary>
/// Determines if a particular message Type is registered.
/// </summary>
/// <param name="type">The type of the message.</param>
View
19 ReactiveUI/MessageBus.cs
@@ -54,6 +54,23 @@ public IObservable<T> Listen<T>(string contract = null)
{
this.Log().Info("Listening to {0}:{1}", typeof (T), contract);
+ return SetupSubjectIfNecessary<T>(contract).Skip(1);
+ }
+
+ /// <summary>
+ /// Listen provides an Observable that will fire whenever a Message is
+ /// provided for this object via RegisterMessageSource or SendMessage.
+ /// </summary>
+ /// <typeparam name="T">The type of the message to listen to.</typeparam>
+ /// <param name="contract">A unique string to distinguish messages with
+ /// identical types (i.e. "MyCoolViewModel") - if the message type is
+ /// only used for one purpose, leave this as null.</param>
+ /// <returns>An Observable representing the notifications posted to the
+ /// message bus.</returns>
+ public IObservable<T> ListenIncludeLatest<T>(string contract = null)
+ {
+ this.Log().Info("Listening to {0}:{1}", typeof(T), contract);
+
return SetupSubjectIfNecessary<T>(contract);
}
@@ -126,7 +143,7 @@ ISubject<T> SetupSubjectIfNecessary<T>(string contract)
return;
}
- ret = new ScheduledSubject<T>(GetScheduler(tuple));
+ ret = new ScheduledSubject<T>(GetScheduler(tuple), null, new BehaviorSubject<T>(default(T)));
mb[tuple] = new NotAWeakReference(ret);
});
Please sign in to comment.
Something went wrong with that request. Please try again.