PureMVC Architects Lounge

PureMVC Manifold => Multicore Version => Topic started by: mikebritton on January 21, 2012, 01:34:42



Title: Registering and retrieving a proxy
Post by: mikebritton on January 21, 2012, 01:34:42
Can't seem to retrieve my proxy once I've registered it:

:
var facade = Facade.getInstance('ApplicationFacade');
   
 facade.registerProxy(new StoryProxy(StoryProxy.NAME, []));

Then elsewhere, after StroyProxy's onRegister fires:

:
var prox = facade.retrieveProxy(StoryProxy.NAME);
console.dir(prox); // undefined

My proxy (probably where the problem is):

:
function StoryProxy(name, component) {
    console.log('new StoryProxy: '+name);
    Proxy.call(name);
}

StoryProxy.prototype = new Proxy;
StoryProxy.prototype.constructor = StoryProxy;

StoryProxy.NAME = 'StoryProxy';

/** @override */
StoryProxy.prototype.initializeNotifier = function() {
    console.log('StoryProxy::initializeNotifier'); 
};
StoryProxy.prototype.onRegister = function() {
    console.log('StoryProxy::onRegister'); 
    var facade = Facade.getInstance('ApplicationFacade');
    facade.sendNotification(Application.NOTE_GET_STORIES);
};

Thanks in advance!


Title: Re: Registering and retrieving a proxy
Post by: davidfoley on January 22, 2012, 10:51:43
Hi Mike,

this is pretty straightforward- I think you may have just overlooked calling the Proxy super constructor properly. Rather than
:
function StoryProxy(name, component) {
    console.log('new StoryProxy: '+name);
    Proxy.call(name);
}
try
:
function StoryProxy(name, component) {
    console.log('new StoryProxy: '+name);
    // invoke Proxy using the StoryProxy instance as the execution scope
    Proxy.call(this, name);
}
Its easy to overlook, but when invoking super constructors with call or apply, just remember to pass in an instance of the subclass the first argument. Note that you can use apply to invoke a super constructor without having to define specific arguments.
:
function StoryProxy ()
{
    Proxy.apply(this, arguments);
}

Hope this works for you.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply)