[Ironruby-core] Events?

Sean Clark Hess seanhess at gmail.com
Fri Aug 15 08:12:00 EDT 2008


Awesome, thanks for the example Ivan.  It's good to see it done "correctly"
;P   Actually, mine includes the sender of the event and an event object to,
I just wasn't paying attention to them in the handler example, but yours is
definitely more formal.  Thanks again

On Fri, Aug 15, 2008 at 12:28 AM, Ivan Porto Carrero <ivan at flanders.co.nz>wrote:

> I actually use a customized version of Observable that includes the sender
> of the event.
> It's that approach but a little bit more formalized. It's in the IronNails
> framework
> http://github.com/casualjim/ironnails/tree/master/IronNails/vendor/iron_nails/lib/observable.rb
> That should look a lot like how events are implemented in C#.
>
>
>
> 2008/8/15 Sean Clark Hess <seanhess at gmail.com>
>
> Cool... that's pretty much what I did.  Thanks
>>
>> On Thu, Aug 14, 2008 at 4:08 PM, Tomas Matousek <
>> Tomas.Matousek at microsoft.com> wrote:
>>
>>>  It seems that both parts of the code are Ruby. So you should use Ruby
>>> language features. It's possible to emulate CLR events by a list of blocks.
>>>
>>>
>>>
>>> event = []
>>>
>>>
>>>
>>> # adding a handler:
>>>
>>> handler = lambda { … }
>>>
>>> event << handler
>>>
>>>
>>>
>>> # removing a handler:
>>>
>>> event.delete handler
>>>
>>>
>>>
>>> # firing an event:
>>>
>>> event.each { |handler| handler[args] }
>>>
>>>
>>>
>>> Tomas
>>>
>>>
>>>
>>> *From:* ironruby-core-bounces at rubyforge.org [mailto:
>>> ironruby-core-bounces at rubyforge.org] *On Behalf Of *Sean Clark Hess
>>> *Sent:* Thursday, August 14, 2008 1:29 PM
>>> *To:* ironruby-core at rubyforge.org
>>> *Subject:* Re: [Ironruby-core] Events?
>>>
>>>
>>>
>>> Let's say I create a class called MovieControls, that wraps some existing
>>> xaml.  The xaml has several buttons, including a toggle play/pause button,
>>> and a previous and next button.
>>>
>>>
>>>
>>> MovieControls would listen to the click of the play/pause button, and
>>> would dispatch a "play" event when they clicked it to play it, and "pause"
>>> for the opposite.
>>>
>>>
>>>
>>> I want to be able to listen to MovieControls to know when to tell my
>>> video to "play" and "pause".
>>>
>>>
>>>
>>> So, it would be something like this...  In MovieControls
>>>
>>> play_pause_button.click { if (isPlayState) dispatch("play") else
>>> dispatch("pause") end }
>>>
>>>
>>>
>>> Then, in my app
>>>
>>> myMovieControls.play { doPlay }
>>>
>>> myMovieControls.pause { doPause }
>>>
>>>
>>>
>>> Does that make more sense now? If this seems totally out of the blue, how
>>> are people currently handling abstracting away this kind of functionality?
>>>
>>>
>>>
>>> Thanks
>>>
>>> ~sean
>>>
>>>
>>>
>>> On Thu, Aug 14, 2008 at 2:22 PM, Tomas Matousek <
>>> Tomas.Matousek at microsoft.com> wrote:
>>>
>>> I'm not sure I understand the scenario. Would you like to declare an
>>> event on Ruby object that you want to hook from C# code? Like
>>> rubyEngine.Operations.GetMember(obj, "my_event") += delegate { ...}?
>>>
>>>
>>>
>>> Tomas
>>>
>>>
>>>
>>> *From:* ironruby-core-bounces at rubyforge.org [mailto:
>>> ironruby-core-bounces at rubyforge.org] *On Behalf Of *Sean Clark Hess
>>> *Sent:* Thursday, August 14, 2008 12:04 PM
>>> *To:* ironruby-core at rubyforge.org
>>> *Subject:* [Ironruby-core] Events?
>>>
>>>
>>>
>>> Hi all,
>>>
>>>
>>>
>>> Is there a built-in event system for IronRuby?  I know I can handle
>>> events with button.click { }, but what if I want to dispatch my own, custom
>>> events (from a class I created myself?).
>>>
>>>
>>>
>>> I wrote my own event system, but I would prefer to use a built-in
>>> dispatch method if it exists.
>>>
>>>
>>>
>>> Thanks!
>>>
>>> ~sean
>>>
>>>
>>> _______________________________________________
>>> Ironruby-core mailing list
>>> Ironruby-core at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/ironruby-core
>>>
>>>
>>>
>>> _______________________________________________
>>> Ironruby-core mailing list
>>> Ironruby-core at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/ironruby-core
>>>
>>>
>>
>> _______________________________________________
>> Ironruby-core mailing list
>> Ironruby-core at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/ironruby-core
>>
>>
>
>
> --
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero
> GSM: +32.486.787.582
> Blog: http://flanders.co.nz
> Twitter: http://twitter.com/casualjim
>
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20080815/0572bc10/attachment-0001.html>


More information about the Ironruby-core mailing list