oyvindkinsey/easyXDM — pull request #235 by nevans54 (2013-08-14 23:38:49+00:00)
Title: Set function context in easyXDM.Rpc

Hello! Great library!

I have created the ability to set context for the `local` functions exposed in an easyXDM.Rpc instance.
You can set context by setting a new `context` config parameter in the channel configuration.

new easyXDM.Rpc({
...
context: window,
...
}

The reason I needed this functionality is because I have a Backbone model that is wrapping the Rpc object. I wanted to have control over my functions from the Backbone model itself, plus I wanted my functions exposed in the Rpc object to be easier to test.

providerRPC = Backbone.Model.extend({
defaults: {
xdmrpc: null,
local: '/js/easyXDM/name.html',
swf: '/js/easyXDM/easyxdm.swf'
},
initialize: function () {
this.set('xdmrpc', this.createXDM());
},
createXDM: function () {
// this backbone model
var me = this;

return new easyXDM.Rpc( {
context: me,
local: me.get('local'),
swf: me.get('swf')
}, {
remote: {
updateOrder: {}
},
local: {
startup: me.startup
}
});
},
startup: function (data, success, error) {
// this == the backbone model
this.authenticate(data);
return true;
},
authenticate: function (data) {
alert("You may pass!");
}
});

Thanks!

Nate