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