On Fri, Jul 31, 2009 at 5:00 AM, Arne Roomann-Kurrik <[email protected]>wrote:

> I've been doing a little bit of work with a test container rendering
> multiple gadgets and was trying to set up gadgets.rpc.  As far as I can
> tell, if I set the "name" property of the gadget iframe, I can access this
> property under "this.f" in the RPC callback.  I was wondering whether this
> was the expected way to tie a given iframe with an RPC response, and will
> it
> work on every transport mechanism? Or is there some extra iframe
> registration step I'm missing?


Yes, it is what's expected. Unfortunately this behavior is documented in the
middle of the rpc.js source, so it's not so obvious how this should work.

I'd vote for making it more obvious by passing the arguments that are
attached to the scope to the first argument of the RPCs, but it's hard to do
that and be compatible 2 years after the fact.

I'd recommend using this pattern in the container to make gadgets.rpc more
usable:

function wrapRpcCallback(func) {
  return function() {
    var args = [{from: this.f, .. other fields...}];
    for (var i = 0, j = arguments.length; i < j; ++i) {
      args.push(arguments[i]);
    }
    func.apply(null, args);
   }
}

gadgets.rpc.register("showGadgetDescription",
wrapRpcCallback(function(context, arg0, arg1, ...) {
  var dataForGadget = getDataForGadget(context.from);
  alert(dataForGadget.description);
}));


>
>
> Thanks,
> ~Arne
>

Reply via email to