flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pio...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - - Add CollectionEvent - Use CollectionEvent in ArrayList to notify interested listeners what items has changed - added/removed or updated
Date Wed, 01 Mar 2017 20:07:22 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop f5a16cabb -> 006d94b44


- Add CollectionEvent
- Use CollectionEvent in ArrayList to notify interested listeners what items has changed -
added/removed or updated


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/006d94b4
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/006d94b4
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/006d94b4

Branch: refs/heads/develop
Commit: 006d94b44b772838d6564be40d81223ae9d8dd61
Parents: f5a16ca
Author: piotrz <piotrz@apache.org>
Authored: Wed Mar 1 21:07:19 2017 +0100
Committer: piotrz <piotrz@apache.org>
Committed: Wed Mar 1 21:07:19 2017 +0100

----------------------------------------------------------------------
 .../org/apache/flex/collections/ArrayList.as    | 57 +++++++++----
 .../projects/Core/src/main/flex/CoreClasses.as  |  1 +
 .../org/apache/flex/core/ISelectionModel.as     |  2 -
 .../org/apache/flex/events/CollectionEvent.as   | 88 ++++++++++++++++++++
 4 files changed, 128 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/006d94b4/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as
b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as
index 6f26e25..fe74932 100644
--- a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as
+++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as
@@ -23,8 +23,7 @@ package org.apache.flex.collections
 	import org.apache.flex.events.Event;
 	import org.apache.flex.events.EventDispatcher;
 	import org.apache.flex.events.IEventDispatcher;
-    import org.apache.flex.collections.parsers.IInputParser;
-    import org.apache.flex.collections.converters.IItemConverter;
+    import org.apache.flex.events.CollectionEvent;
 
     //--------------------------------------
     //  Events
@@ -39,7 +38,7 @@ package org.apache.flex.collections
 	 *  @playerversion AIR 2.6
 	 *  @productversion FlexJS 0.0
 	 */
-	[Event(name="collectionChanged", type="org.apache.flex.events.Event")]
+	[Event(name="collectionChanged", type="org.apache.flex.events.CollectionEvent")]
 
 	/**
 	 *  Dispatched when the collection has added an item.
@@ -49,7 +48,7 @@ package org.apache.flex.collections
 	 *  @playerversion AIR 2.6
 	 *  @productversion FlexJS 0.0
 	 */
-	[Event(name="itemAdded", type="org.apache.flex.events.Event")]
+	[Event(name="itemAdded", type="org.apache.flex.events.CollectionEvent")]
 
 	/**
 	 *  Dispatched when the collection has removed an item.
@@ -59,7 +58,7 @@ package org.apache.flex.collections
 	 *  @playerversion AIR 2.6
 	 *  @productversion FlexJS 0.0
 	 */
-	[Event(name="itemRemoved", type="org.apache.flex.events.Event")]
+	[Event(name="itemRemoved", type="org.apache.flex.events.CollectionEvent")]
 
 	/**
 	 *  Dispatched when the collection has updated an item.
@@ -69,7 +68,7 @@ package org.apache.flex.collections
 	 *  @playerversion AIR 2.6
 	 *  @productversion FlexJS 0.0
 	 */
-	[Event(name="itemUpdated", type="org.apache.flex.events.Event")]
+	[Event(name="itemUpdated", type="org.apache.flex.events.CollectionEvent")]
 
     /**
      *  The ArrayList class provides an event-driven wrapper for the
@@ -159,9 +158,16 @@ package org.apache.flex.collections
 		public function set source(value:Array):void
 		{
 			if (_source != value) {
-				if (value == null) _source = [];
-				else _source = value;
-				dispatchEvent(new Event("collectionChanged"));
+				if (value == null)
+				{
+					_source = [];
+                }
+				else
+				{
+					_source = value;
+                }
+
+				dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGED));
 			}
 		}
 
@@ -252,7 +258,9 @@ package org.apache.flex.collections
 				return;
 			}
 
-			dispatchEvent(new Event("itemAdded"));
+			var collectionEvent:CollectionEvent = new CollectionEvent(CollectionEvent.ITEM_ADDED);
+			collectionEvent.item = item;
+			dispatchEvent(collectionEvent);
 		}
 
 		/**
@@ -272,7 +280,10 @@ package org.apache.flex.collections
 			if (index >= 0 && index < spliceUpperBound) {
 				oldItem = source[index];
 				source[index] = item;
-				dispatchEvent(new Event("itemUpdated"));
+
+                var collectionEvent:CollectionEvent = new CollectionEvent(CollectionEvent.ITEM_UPDATED);
+                collectionEvent.item = item;
+				dispatchEvent(collectionEvent);
 			}
 			else {
 				// error
@@ -330,7 +341,10 @@ package org.apache.flex.collections
 				return null;
 			}
 
-			dispatchEvent(new Event("itemRemoved"));
+            var collectionEvent:CollectionEvent = new CollectionEvent(CollectionEvent.ITEM_REMOVED);
+            collectionEvent.item = removed;
+            dispatchEvent(collectionEvent);
+
 			return removed;
 		}
 
@@ -344,9 +358,11 @@ package org.apache.flex.collections
 		 */
 		public function removeAll():void
 		{
-			if (length > 0) {
-				source.splice(0, length);
-				dispatchEvent(new Event("itemRemoved"));
+			if (length > 0)
+			{
+                var collectionEvent:CollectionEvent = new CollectionEvent(CollectionEvent.ITEM_REMOVED);
+                collectionEvent.items = source.splice(0, length);
+                dispatchEvent(collectionEvent);
 			}
 		}
 
@@ -361,8 +377,11 @@ package org.apache.flex.collections
 		public function itemUpdated(item:Object):void
 		{
 			var index:int = getItemIndex(item);
-			if (index >= 0) {
-				dispatchEvent(new Event("itemUpdated"));
+			if (index >= 0)
+			{
+                var collectionEvent:CollectionEvent = new CollectionEvent(CollectionEvent.ITEM_UPDATED);
+                collectionEvent.item = item;
+                dispatchEvent(collectionEvent);
 			}
 		}
 
@@ -376,7 +395,9 @@ package org.apache.flex.collections
 		 */
 		public function itemUpdatedAt(index:int):void
 		{
-			dispatchEvent(new Event("itemUpdated"));
+            var collectionEvent:CollectionEvent = new CollectionEvent(CollectionEvent.ITEM_UPDATED);
+            collectionEvent.item = getItemAt(index);
+            dispatchEvent(collectionEvent);
 		}
 
         /**

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/006d94b4/frameworks/projects/Core/src/main/flex/CoreClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as
index 690d84c..744242a 100644
--- a/frameworks/projects/Core/src/main/flex/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as
@@ -110,6 +110,7 @@ internal class CoreClasses
 	import org.apache.flex.core.StyleChangeNotifier; StyleChangeNotifier;
 	import org.apache.flex.events.CustomEvent; CustomEvent;
     import org.apache.flex.events.Event; Event;
+	import org.apache.flex.events.CollectionEvent; CollectionEvent;
     import org.apache.flex.events.ProgressEvent; ProgressEvent;
 	import org.apache.flex.events.StyleChangeEvent; StyleChangeEvent;
     import org.apache.flex.events.EventDispatcher; EventDispatcher;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/006d94b4/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ISelectionModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ISelectionModel.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ISelectionModel.as
index 3068286..cab9c01 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ISelectionModel.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ISelectionModel.as
@@ -18,8 +18,6 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.core
 {
-	import org.apache.flex.events.IEventDispatcher;
-
     /**
      *  The ISelectionModel interface describes the minimum set of properties
      *  available to control that let the user select from within a

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/006d94b4/frameworks/projects/Core/src/main/flex/org/apache/flex/events/CollectionEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/CollectionEvent.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/CollectionEvent.as
new file mode 100644
index 0000000..3fc239b
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/CollectionEvent.as
@@ -0,0 +1,88 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.events
+{
+
+	/**
+	 * The CollectionEvent class is used for dispatching an collection events
+	 *
+	 * @langversion 3.0
+	 * @playerversion Flash 10.2
+	 * @playerversion AIR 2.6
+	 * @productversion FlexJS 0.8.0
+	 */
+	public class CollectionEvent extends Event
+	{
+		public static const ITEM_ADDED:String = "itemAdded";
+		public static const ITEM_REMOVED:String = "itemRemoved";
+		public static const ITEM_UPDATED:String = "itemUpdated";
+		public static const COLLECTION_CHANGED:String = "collectionChanged";
+
+		//--------------------------------------
+		//   Constructor
+		//--------------------------------------
+
+		/**
+		 * Constructor.
+		 *
+		 * @param type The name of the event.
+		 * @param bubbles Whether the event bubbles.
+		 * @param cancelable Whether the event can be canceled.
+		 *
+		 * @langversion 3.0
+		 * @playerversion Flash 10.2
+		 * @playerversion AIR 2.6
+		 * @productversion FlexJS 0.8.0
+		 */
+		public function CollectionEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
+		{
+            super(type, bubbles, cancelable);                    
+		}
+
+        /**
+         * The item being removed/added/updated
+         *
+         * @langversion 3.0
+         * @playerversion Flash 10.2
+         * @playerversion AIR 2.6
+         * @productversion FlexJS 0.8.0
+         */
+        public var item:Object;
+
+        /**
+         * The items being removed
+         *
+         * @langversion 3.0
+         * @playerversion Flash 10.2
+         * @playerversion AIR 2.6
+         * @productversion FlexJS 0.8.0
+         */
+		public var items:Array;
+
+        override public function cloneEvent():IFlexJSEvent
+        {
+            var collectionEvent:CollectionEvent = new CollectionEvent(type, bubbles, cancelable);
+			collectionEvent.item = item;
+			collectionEvent.items = items;
+
+			return collectionEvent;
+        }
+    }
+}


Mime
View raw message