I needed the ability to have two or more objects of the same type talk
to each other and respond to each others events. For example when one
gets updated the other one should also do something. My first thought
was to use MochiKit.Signal.signal but that needs a source as a first
arg so that is not good because i do not know the name of the other
object so i modified signal and came up with

MochiKit.Base.update(MochiKit.Signal,{
        'signalAll' : function(sig){
                var self= MochiKit.Signal;
                var observers = self._observers;
                var args = MochiKit.Base.extend(null, arguments, 1);
                var errors = [];
        self._lock = true;
        for (var i = 0; i < observers.length; i++) {
            var ident = observers[i];
            if (ident.signal === sig && ident.connected) {
                try {
                    ident.listener.apply(ident.source, args);
                } catch (e) {
                    errors.push(e);
                }
            }
        }
                self._lock = false;
        if (self._dirty) {
            self._dirty = false;
            for (var i = observers.length - 1; i >= 0; i--) {
                if (!observers[i].connected) {
                    observers.splice(i, 1);
                }
            }
        }
                if (errors.length == 1) {
            throw errors[0];
        } else if (errors.length > 1) {
            var e = new Error("Multiple errors thrown in handling
'sig', see errors property");
            e.errors = errors;
            throw e;
        }
        }
});

Basicly you can now just call MochiKit.Signal.signalAll('onupdate');
and every object connected to that signal will get notified.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to