flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [20/30] git commit: [flex-asjs] [refs/heads/spark] - Modified TodoListSample to take advantage of itemRendererCreated event from DataItemFactory* class.
Date Wed, 14 Sep 2016 21:31:10 GMT
Modified TodoListSample to take advantage of itemRendererCreated event from DataItemFactory*
class.


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

Branch: refs/heads/spark
Commit: e87787017f689ff0b85b231f28c17be9a703b95b
Parents: db261ad
Author: Peter Ent <pent@apache.org>
Authored: Thu Sep 8 14:26:35 2016 -0400
Committer: Peter Ent <pent@apache.org>
Committed: Thu Sep 8 14:26:35 2016 -0400

----------------------------------------------------------------------
 .../renderers/TodoListItemRendererFactory.as    | 68 --------------------
 .../src/sample/todo/views/TodoListView.mxml     | 53 ++++++++++-----
 2 files changed, 36 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e8778701/examples/flexjs/TodoListSampleApp/src/sample/todo/renderers/TodoListItemRendererFactory.as
----------------------------------------------------------------------
diff --git a/examples/flexjs/TodoListSampleApp/src/sample/todo/renderers/TodoListItemRendererFactory.as
b/examples/flexjs/TodoListSampleApp/src/sample/todo/renderers/TodoListItemRendererFactory.as
deleted file mode 100644
index 54f11ff..0000000
--- a/examples/flexjs/TodoListSampleApp/src/sample/todo/renderers/TodoListItemRendererFactory.as
+++ /dev/null
@@ -1,68 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-//
-//  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 sample.todo.renderers {
-
-	import org.apache.flex.core.ISelectableItemRenderer;
-	import org.apache.flex.core.IStrand;
-	import org.apache.flex.events.Event;
-	import org.apache.flex.events.IEventDispatcher;
-	import org.apache.flex.html.beads.DataItemRendererFactoryAndEventDispatcherForArrayData;
-
-	import sample.todo.events.TodoListEvent;
-	import sample.todo.renderers.TodoItemRenderer;
-
-	[Event(name="itemChecked", type="sample.todo.events.TodoListEvent")]
-	[Event(name="itemRemoveRequest", type="sample.todo.events.TodoListEvent")]
-
-	public class TodoListItemRendererFactory extends DataItemRendererFactoryAndEventDispatcherForArrayData
{
-
-
-		private var _strand:IStrand;
-
-		override public function set strand(value:IStrand):void
-		{
-			super.strand = value;
-			_strand = value;
-		}
-
-		override protected function itemRendererCreated(ir:ISelectableItemRenderer):void
-		{
-			IEventDispatcher(ir).addEventListener("checkChanged",itemChecked);
-			IEventDispatcher(ir).addEventListener("removeRequest",itemRemove);
-		}
-
-		private function itemChecked(event:Event):void
-		{
-			var renderer:TodoItemRenderer = event.target as TodoItemRenderer;
-
-			var newEvent:TodoListEvent = new TodoListEvent(TodoListEvent.ITEM_CHECKED);
-			newEvent.item = renderer.data;
-			dispatchEvent(newEvent);
-		}
-
-		private function itemRemove(event:Event):void
-		{
-			var renderer:TodoItemRenderer = event.target as TodoItemRenderer;
-
-			var newEvent:TodoListEvent = new TodoListEvent(TodoListEvent.ITEM_REMOVE_REQUEST);
-			newEvent.item = renderer.data;
-			dispatchEvent(newEvent);
-		}
-	}
-}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e8778701/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml
----------------------------------------------------------------------
diff --git a/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml b/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml
index 310cfc0..9ddf675 100644
--- a/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml
+++ b/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml
@@ -26,6 +26,8 @@ limitations under the License.
     <fx:Script>
 		<![CDATA[
 			import org.apache.flex.events.Event;
+			import org.apache.flex.events.IEventDispatcher;
+			import org.apache.flex.events.ItemRendererEvent;
 			import org.apache.flex.html.beads.controllers.ItemRendererMouseController;
 			
 			import sample.todo.events.TodoListEvent;
@@ -52,13 +54,6 @@ limitations under the License.
 				todoInput.text = "";
 			}
 			
-			private function forwardEvent(event:TodoListEvent):void
-			{
-				var newEvent:TodoListEvent = new TodoListEvent(event.type);
-				newEvent.item = event.item;
-				dispatchEvent(newEvent);
-			}
-			
 			private function updateStatus(event:org.apache.flex.events.Event):void {
 				var numberLeft:Number = 0;
 				
@@ -92,6 +87,39 @@ limitations under the License.
 			private function showCompleted():void {
 				(applicationModel as TodoListModel).showCompletedTodos();
 			}
+			
+			/**
+			 * Handle creation of itemRenderers by listening for the events they dispatch.
+			 */
+			private function handleRendererCreated(event:ItemRendererEvent):void {
+				var renderer:IEventDispatcher = event.itemRenderer as IEventDispatcher;
+				renderer.addEventListener("checkChanged",itemChecked);
+				renderer.addEventListener("removeRequest",itemRemove);
+			}
+			
+			/**
+			 * When an item is checked, form new event and dispatch to controller.
+			 */
+			private function itemChecked(event:Event):void
+			{
+				var renderer:TodoItemRenderer = event.target as TodoItemRenderer;
+
+				var newEvent:TodoListEvent = new TodoListEvent(TodoListEvent.ITEM_CHECKED);
+				newEvent.item = renderer.data;
+				dispatchEvent(newEvent);
+			}
+
+			/**
+			 * When an item is removed, form a new event and dispatch to the controller.
+			 */
+			private function itemRemove(event:Event):void
+			{
+				var renderer:TodoItemRenderer = event.target as TodoItemRenderer;
+
+				var newEvent:TodoListEvent = new TodoListEvent(TodoListEvent.ITEM_REMOVE_REQUEST);
+				newEvent.item = renderer.data;
+				dispatchEvent(newEvent);
+			}
         ]]>
 	</fx:Script>
 	
@@ -115,8 +143,7 @@ limitations under the License.
 					dataProvider="{TodoListModel(applicationModel).todos}"
                     width="100%" height="400">
 			<js:beads>
-				<renderers:TodoListItemRendererFactory itemChecked="forwardEvent(event)" 
-													   itemRemoveRequest="forwardEvent(event)" />
+				<js:DataItemRendererFactoryForArrayData itemRendererCreated="handleRendererCreated(event)"
/>
 			</js:beads>
         </js:List>
 
@@ -135,14 +162,6 @@ limitations under the License.
         @namespace basic "library://ns.apache.org/flexjs/basic";
         @namespace renderers "sample.todo.renderers.*";
 
-        /* use className="todoList" on the List element in place of itemRenderer if you want
to specify
-         * the itemRenderer in a style definition along with other settings.
-         */
-        .todoList {
-            IDataProviderItemRendererMapper: ClassReference("org.apache.flex.html.beads.DataItemRendererFactoryForArrayData");
-            IItemRenderer: ClassReference("sample.todo.renderers.TodoItemRenderer");
-        }
-
         renderers|TodoItemRenderer {
 			backgroundColor: #FFFFFF;
             height: 40px;


Mime
View raw message