Hi Chris,
To make a command invoked when a message comes in:
MessageBus.Current.Listen<FooType>().InvokeCommand(myCoolCommand);
which is shorthand for
var myCoolCommand = new ReactiveCommand();
MessageBus.Current.Listen<FooType>()
.Subscribe(x => {
if (!myCoolCommand.CanExecute(x)) return;
myCoolCommand.Execute(x);
});
To *send* a message when a command is invoked, it'd be:
var myCoolCommand = new ReactiveCommand();
MessageBus.Current.RegisterMessageSource(
myCoolCommand.Select(_ => someDataIWantToPassAlong));
Let me know if these examples make no sense and I can explain them :)
--
Paul Betts <
pa...@paulbetts.org>
On Tue, May 21, 2013 at 11:50:04AM -0700, Chris Dickerson wrote:
> I am having trouble with *ReactiveCommand*, attaching it to a button and
> showing a response.
>
> *MessageBus* - from what I can tell, you have to register, listen/send.
> Whether I give a name for the contract or not... nothing's working. My
> goal is simply to create a message that can be subscribed to by any other
> view and a message can be sent to the listener(s). Or is the *MessageBus*something entirely different? I found that
> *IReactiveCommand* is an acceptable source for the registration but... not
> sure how to bind it to a button and use it to send messages?
>
> *RegisterMessageSource(IObservable source)* – Register an IObservable as a
> message source – anything that is published on the IObservable gets
> published to the bus.
> *SendMessage(message)* – Publish a single item on the bus instead of having
> to use an Observable.
> *IObservable Listen()* – Get an Observable for the specified source – you
> can either Subscribe to it directly, or use any of the Rx operators to
> filter what you want.
>
> The few examples I can find, have very simple solutions, usually a
> Console.WriteLine printing out some value. When I try to use a method in
> it's place -- no dice.
>
> Admittedly I don't have as firm a grasp on LINQ or anonymous methods when
> it comes to these examples...
>
>
http://rxwiki.wikidot.com/101samples
>
> *var* cmd = new *ReactiveCommand*(_ => true, Console.WriteLine);
> cmd.CanExecute(*null*);
> >> *true*
>
>
>
> cmd.Execute("Hello");
> "Hello"
>
> I was able to implement ICommand via a separate class. I suppose I was
> under the impression that you could do this with ReactiveCommand without
> requiring a separate class file.
>
> --
> You received this message because you are subscribed to the Google Groups "ReactiveUI mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
reactivexaml...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>