You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by la...@apache.org on 2012/04/10 20:36:15 UTC
svn commit: r1311914 - in
/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections:
ArrayList.as VectorList.as tests/arrayList/EventsTest.as
tests/vectorList/EventsTest.as
Author: labriola
Date: Tue Apr 10 18:36:14 2012
New Revision: 1311914
URL: http://svn.apache.org/viewvc?rev=1311914&view=rev
Log:
Modification to ArrayList and VectorList to correctly find the index when itemUpdated() is invoked. Modifications to the unit tests to demonstrate and test this new behavior
Modified:
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/EventsTest.as
Modified: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as?rev=1311914&r1=1311913&r2=1311914&view=diff
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as (original)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as Tue Apr 10 18:36:14 2012
@@ -568,8 +568,17 @@ public class ArrayList extends EventDisp
event.property = property;
event.oldValue = oldValue;
event.newValue = newValue;
-
- itemUpdateHandler(event);
+
+ //This handler was intended to handle events from child objects, not to be called directly
+ //itemUpdateHandler(event);
+
+ internalDispatchEvent(CollectionEventKind.UPDATE, event);
+
+ // need to dispatch object event now
+ if (_dispatchEvents == 0 && hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
+ {
+ dispatchPropertyChangeEventClone( event, item );
+ }
}
/**
@@ -634,6 +643,26 @@ public class ArrayList extends EventDisp
//
//--------------------------------------------------------------------------
+ /**
+ * Dispatches a PropertyChangeEvent clone either from a child object whose event needs to be redispatched
+ * or when a PropertyChangeEvent is faked inside of this class for the purposes of informing the view
+ * of an update to underlying data.
+ *
+ * @param event The PropertyChangeEvent to be cloned and dispatched
+ * @param item The item within the view that was updated.
+ *
+ * @see mx.core.IPropertyChangeNotifier
+ * @see mx.events.PropertyChangeEvent
+ */
+
+ private function dispatchPropertyChangeEventClone( event:PropertyChangeEvent, item:Object ):void {
+ var objEvent:PropertyChangeEvent = PropertyChangeEvent(event.clone());
+
+ var index:int = getItemIndex( item );
+ objEvent.property = index.toString() + "." + event.property;
+ dispatchEvent(objEvent);
+ }
+
/**
* Enables event dispatch for this list.
*
@@ -721,17 +750,12 @@ public class ArrayList extends EventDisp
protected function itemUpdateHandler(event:PropertyChangeEvent):void
{
internalDispatchEvent(CollectionEventKind.UPDATE, event);
- // need to dispatch object event now
- if (_dispatchEvents == 0 && hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
- {
- var objEvent:PropertyChangeEvent = PropertyChangeEvent(event.clone());
- //When itemUpdated is called, there is no event target. This means getItemIndex returns a -1
- //Since this was originally cast as a uint, this caused many strange results. Changing it to
- //an int to be consistent throughout other uses of this event
- var index:int = getItemIndex(event.target);
- objEvent.property = index.toString() + "." + event.property;
- dispatchEvent(objEvent);
- }
+
+ // need to dispatch object event now
+ if (_dispatchEvents == 0 && hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
+ {
+ dispatchPropertyChangeEventClone( event, event.target );
+ }
}
/**
Modified: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as?rev=1311914&r1=1311913&r2=1311914&view=diff
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as (original)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as Tue Apr 10 18:36:14 2012
@@ -470,9 +470,15 @@ public class VectorList extends EventDis
event.oldValue = oldValue;
event.newValue = newValue;
- itemUpdateHandler(event);
+ internalDispatchEvent(CollectionEventKind.UPDATE, event);
+
+ // need to dispatch object event now
+ if (_dispatchEvents == 0 && hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
+ {
+ dispatchPropertyChangeEventClone( event, item );
+ }
}
-
+
/**
* Return an Vector that is populated in the same order as the IList
* implementation.
@@ -506,6 +512,26 @@ public class VectorList extends EventDis
//--------------------------------------------------------------------------
/**
+ * Dispatches a PropertyChangeEvent clone either from a child object whose event needs to be redispatched
+ * or when a PropertyChangeEvent is faked inside of this class for the purposes of informing the view
+ * of an update to underlying data.
+ *
+ * @param event The PropertyChangeEvent to be cloned and dispatched
+ * @param item The item within the view that was updated.
+ *
+ * @see mx.core.IPropertyChangeNotifier
+ * @see mx.events.PropertyChangeEvent
+ */
+
+ private function dispatchPropertyChangeEventClone( event:PropertyChangeEvent, item:Object ):void {
+ var objEvent:PropertyChangeEvent = PropertyChangeEvent(event.clone());
+
+ var index:int = getItemIndex( item );
+ objEvent.property = index.toString() + "." + event.property;
+ dispatchEvent(objEvent);
+ }
+
+ /**
* Enables event dispatch for this list.
*/
private function enableEvents():void
@@ -573,10 +599,7 @@ public class VectorList extends EventDis
// need to dispatch object event now
if (_dispatchEvents == 0 && hasEventListener(PropertyChangeEvent.PROPERTY_CHANGE))
{
- var objEvent:PropertyChangeEvent = PropertyChangeEvent(event.clone());
- var index:int = getItemIndex(event.target);
- objEvent.property = index.toString() + "." + event.property;
- dispatchEvent(objEvent);
+ dispatchPropertyChangeEventClone( event, event.target );
}
}
Modified: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as?rev=1311914&r1=1311913&r2=1311914&view=diff
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as (original)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as Tue Apr 10 18:36:14 2012
@@ -233,6 +233,7 @@ package mx.collections.tests.arrayList {
[Test(description="This test relies upon the patched version of ArrayList in my whiteboard")]
public function itemUpdatedShouldDispatchPropertyChangeEvent():void {
+ const index:int = 1;
const propertyName:String = "dummy";
const propertyOldVal:String = "dummyOldVal";
const propertyNewVal:String = "dummyNewVal";
@@ -241,7 +242,8 @@ package mx.collections.tests.arrayList {
var eventDispatcher:EventDispatcher = new EventDispatcher();
var arrayList:ArrayList = new ArrayList( array );
- arrayList.addItem( eventDispatcher );
+ arrayList.addItem( new EventDispatcher() );
+ arrayList.addItemAt( eventDispatcher, index );
expectEvent.from( arrayList ).
hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
@@ -249,7 +251,7 @@ package mx.collections.tests.arrayList {
hasPropertyWithValue( "kind", PropertyChangeEventKind.UPDATE ).
hasPropertyWithValue( "newValue", propertyNewVal ).
hasPropertyWithValue( "oldValue", propertyOldVal ).
- hasPropertyWithValue( "property", "-1" + '.' + propertyName ).
+ hasPropertyWithValue( "property", index + '.' + propertyName ).
hasPropertyWithValue( "source", eventDispatcher ).
once();
Modified: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/EventsTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/EventsTest.as?rev=1311914&r1=1311913&r2=1311914&view=diff
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/EventsTest.as (original)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/EventsTest.as Tue Apr 10 18:36:14 2012
@@ -231,8 +231,9 @@ package mx.collections.tests.vectorList
eventDispatcher.dispatchEvent( PropertyChangeEvent.createUpdateEvent( eventDispatcher, propertyName , propertyOldVal, propertyNewVal ) );
}
- [Test(description="We should really consider if this is the behavior we want here. Right now mimics fixed ArrayList")]
+ [Test]
public function itemUpdatedShouldDispatchPropertyChangeEvent():void {
+ const index:int = 1;
const propertyName:String = "dummy";
const propertyOldVal:String = "dummyOldVal";
const propertyNewVal:String = "dummyNewVal";
@@ -241,7 +242,8 @@ package mx.collections.tests.vectorList
var eventDispatcher:EventDispatcher = new EventDispatcher();
var vectorList:VectorList = new VectorList( vector );
- vectorList.addItem( eventDispatcher );
+ vectorList.addItem( new EventDispatcher() );
+ vectorList.addItemAt( eventDispatcher, index );
expectEvent.from( vectorList ).
hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
@@ -249,7 +251,7 @@ package mx.collections.tests.vectorList
hasPropertyWithValue( "kind", PropertyChangeEventKind.UPDATE ).
hasPropertyWithValue( "newValue", propertyNewVal ).
hasPropertyWithValue( "oldValue", propertyOldVal ).
- hasPropertyWithValue( "property", "-1" + '.' + propertyName ).
+ hasPropertyWithValue( "property", index + '.' + propertyName ).
hasPropertyWithValue( "source", eventDispatcher ).
once();