Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Registering and retrieving a proxy  (Read 5101 times)
mikebritton
Full Member
***
Posts: 42


View Profile Email
« 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!
Logged
davidfoley
Moderator
Newbie
*****
Posts: 8


View Profile Email
« Reply #1 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
« Last Edit: January 22, 2012, 10:55:36 by davidfoley » Logged
Pages: [1]
Print