Jim,

Check this modification of Tobie's code out.
http://gist.github.com/203978
The problem you're describing is fixed by using a unique element to
fire the events from.

Allen Madsen
http://www.allenmadsen.com



On Wed, Oct 7, 2009 at 5:59 AM, Tobie Langel <tobie.lan...@gmail.com> wrote:
>
> Hi again,
>
> For the record, custom events need to be namespaced ('foo:changed',
> not 'changed').
>
> The way you handle namespacing is entirely up to you. It can be
> instance based, class based or arbitrary.
>
> It just needs to be provided by the class / instance itself, and the
> Observable mixin has to take it into account.
>
> Best,
>
> Tobie
>
>
>
>
>
> On Oct 7, 9:50 am, Jim Higson <j...@wikizzle.org> wrote:
>> In another thread I wrote:
>>
>> > The biggest problem with events at the moment is only Elements can fire
>> > them. This makes MVC difficult because the Model (javascript objects) not
>> > the view (HTML elements) would ideally fire the events.
>>
>> > For Prototype2, maybe there should be an observable mixin. When mixed in,
>> > any object can fire events.
>>
>> To which Toby replied:
>>
>> > This is already possible with our current event system using the
>> > `document` object as broker.
>>
>> > Please see a basic, untested implementation here:
>>
>> >http://gist.github.com/203193
>>
>> The implementation linked here is good, but isn't there a problem with:
>>
>> //Foo mixes in Observable
>> var a = new Foo();
>> var b = new Foo();
>>
>> a.observe( 'change', function(){alert( 'a changed' )};
>> b.observe( 'change', function(){alert( 'b changed' )};
>>
>> a.fire('change');
>>
>> // both listeners are now notified even though only object a fired.
>>
>> One fix might be to do:
>>
>> line22:
>> document.fire( this.somethingUnique + eventName, data);
>>
>> line 26:
>> document.observe( this.somethingUnique + eventName, callback);
>>
>> But I don't know where the somethingUnique would come from.
>>
>> Jim
>>
>> --
>> Jim
>> my wiki ajaxification thing:http://wikizzle.org
>> my blog:http://jimhigson.blogspot.com/
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to