Hi Per,
On Fri, Nov 7, 2008 at 10:04, Per Cederberg <[EMAIL PROTECTED]> wrote:
> This is kind of interesting. When using MochiKit.Signal, you would
> depend on the user calling signal() for each change performed, which
> might be unpractical in some cases.
As I understood the example, the objects being modified take care of
calling signal(). E.g. a hash table that fires a signal when objects
are added, removed and even when there's a collision. Guilio Cesare
would like to be able to register for all signals. Perhaps a clearer
API would be to allow wildcards in the second parameter to connect().
> // call the functions and get a deferred objects back
> dispatcher.getUsers();
> dispatcher.updateUser('john', '[EMAIL PROTECTED]');
>
> // connect signals to specific methods (signals on AJAX response)
> connect(dispatcher, "getUsers", doSomething);
This looks neat, and I have something similar implemented in many of
my apps (generally I generate the code from the Python server side -
i.e. any exposed ajax methods automatically get a corresponding JS
function). However, I invariably opt for using deferreds instead of
events.
E.g. what happens in this case:
dispatcher.getUser('john');
dispatcher.getUser('paul');
connect(dispatcher, "getUser", doSomething);
Is doSomething called twice? Because maybe we want to do different
things depending if it is the response for John or for Paul -- and we
don't want to complicate doSomething with code to differentiate
between them.
Also, if (or rather when) we start writing multithreaded JS code -
this becomes a headache. I much prefer
var defrd = dispatcher.getUser('john');
defrd.addCallback(doSomethingWithJohn);
// or simply
dispatcher.getUser('paul').addCallback(doSomehtingWithPaul);
Besides, the ability to chain callbacks (and errbacks) on deferreds
really makes me feel good inside.
function getJSON(...) {
return getHTTP(...).addCallback(decodeJSON);
}
cheers,
Arnar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---