PureMVC Architects Lounge

PureMVC Manifold => Bug Report => Topic started by: meekgeek on November 08, 2007, 06:18:20



Title: [ ODDITY ] TypeError: Error #1006 push is not a function
Post by: meekgeek on November 08, 2007, 06:18:20
Ok, I'm not sure if I'm missing something.

Apparently, if I registerCommand with the string "join" for the first parameter.  I get that error at the top.

As soon as I change it to something else like, "register" it works.

The error leads me to the registerObserver method in the org.puremvc.core.view::View Class.

Is this a reserved word or something?


Title: Re: TypeError: Error #1006 push is not a function
Post by: puremvc on November 08, 2007, 08:08:17
Wow, that is beyond strange.

It all comes down to this evaluation in the View.registerObserver method:

:

if( observerMap[ notificationName ] != null ) {
observerMap[ notificationName ].push( observer );
} else {
observerMap[ notificationName ] = [ observer ];
}

The if statement simply evaluates improperly if that notificationName is the String value 'join'. And it is case sensitive. For instance 'Join' does not cause the problem. Specifically, it acts as though this were true:

:

observerMap[ 'join' ] != null

But it is not. It is as if the string join is being used internally in the actionscript engine. I tried to flush out the problem with the following but could not duplicate the issue.

:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="testHash()"
>
<mx:Script>
<![CDATA[

[Bindable]public var myHash:Array = new Array();
public static const EVILKEY:String = "join";
public static const GOODKEY:String = "kittensAndRadishes";

public function testHash():void
{
myHash[ GOODKEY ] = ["Testing", "a", "good", "key"];
lstGoodKey.dataProvider = myHash[ GOODKEY ];
myHash[ GOODKEY ].push( "OK" );

myHash[ EVILKEY ] = ["Testing", "the", "evil", "key"];
lstEvilKey.dataProvider = myHash[ EVILKEY ];
myHash[ EVILKEY ].push( "OK" );

}

]]>
</mx:Script>
<mx:List id="lstGoodKey"/>
<mx:List id="lstEvilKey"/>
</mx:Application>

Clearly something a little strange is going on. I will do more research to try and figure out how to duplicate the problem outside PureMVC.

For now, just be admonished that 'join' as the key of an associative array appears magical (though not officially reserved in this context) and avoid using it as the constant value in a notification name.

Hardly difficult to work around, but very wierd nonetheless.


Title: Re: TypeError: Error #1006 push is not a function
Post by: meekgeek on November 09, 2007, 10:43:04
Nice to know I wasn't going crazy  :)