This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new d9d6c4d  todomvc: more simplifications and comments
d9d6c4d is described below

commit d9d6c4d1363dca24477740202a74d483f41a0a09
Author: Carlos Rovira <[email protected]>
AuthorDate: Wed Feb 12 19:58:07 2020 +0100

    todomvc: more simplifications and comments
---
 examples/jewel/todomvc/pom.xml                     |  1 -
 examples/jewel/todomvc/src/main/royale/App.mxml    |  2 +-
 .../jewel/todomvc/controllers/TodoController.as    | 93 +++++++++++-----------
 .../main/royale/jewel/todomvc/events/TodoEvent.as  |  3 +-
 .../main/royale/jewel/todomvc/models/TodoModel.as  |  6 --
 .../royale/jewel/todomvc/views/TodoFooter.mxml     |  4 +-
 .../royale/jewel/todomvc/views/TodoHeader.mxml     |  5 +-
 .../jewel/todomvc/views/TodoListSection.mxml       | 10 ++-
 8 files changed, 59 insertions(+), 65 deletions(-)

diff --git a/examples/jewel/todomvc/pom.xml b/examples/jewel/todomvc/pom.xml
index c630438..0bd4f41 100644
--- a/examples/jewel/todomvc/pom.xml
+++ b/examples/jewel/todomvc/pom.xml
@@ -44,7 +44,6 @@
           <debug>false</debug>
           
<htmlTemplate>${basedir}/target/javascript/bin/js-debug/todomvc-index-template.html</htmlTemplate>
           <additionalCompilerOptions>
-            -js-dynamic-access-unknown-members=true;
             -source-map=true;
           </additionalCompilerOptions>
         </configuration>
diff --git a/examples/jewel/todomvc/src/main/royale/App.mxml 
b/examples/jewel/todomvc/src/main/royale/App.mxml
index 9dda280..7220605 100644
--- a/examples/jewel/todomvc/src/main/royale/App.mxml
+++ b/examples/jewel/todomvc/src/main/royale/App.mxml
@@ -49,6 +49,6 @@
 
     <j:initialView>
         <views:TodoListSection/>
-     </j:initialView>
+    </j:initialView>
      
 </j:Application>
diff --git 
a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/controllers/TodoController.as
 
b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/controllers/TodoController.as
index a6f21b3..f4b5db3 100644
--- 
a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/controllers/TodoController.as
+++ 
b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/controllers/TodoController.as
@@ -26,14 +26,14 @@ package jewel.todomvc.controllers
        import org.apache.royale.core.IBeadController;
        import org.apache.royale.core.IBeadModel;
        import org.apache.royale.core.IStrand;
-       import org.apache.royale.events.IEventDispatcher;
+       import org.apache.royale.core.Bead;
 
        /**
      * The Todo Controller holds all the global actions. The views dispatch 
events that bubbles and
         * this class register to these evens and updates the model, so views 
can update accordingly using
         * binding most of the times.
      */
-       public class TodoController implements IBeadController
+       public class TodoController extends Bead implements IBeadController
        {
         /**
                 *  constructor.
@@ -42,8 +42,7 @@ package jewel.todomvc.controllers
                {
         }
 
-        private var _strand:IStrand;
-               /**
+        /**
                 *  @copy org.apache.royale.core.IBead#strand
                 *  
                 *  @langversion 3.0
@@ -51,15 +50,16 @@ package jewel.todomvc.controllers
                 *  @playerversion AIR 2.6
                 *  @productversion Royale 0.9.7
                 */
-               public function set strand(value:IStrand):void {
-                       _strand = value;
-                       (_strand as 
IEventDispatcher).addEventListener(TodoEvent.ADD_TODO_ITEM, addTodoItem);       
     
-                       (_strand as 
IEventDispatcher).addEventListener(TodoEvent.TOGGLE_ALL_COMPLETE, 
toggleAllComplete);            
-                       (_strand as 
IEventDispatcher).addEventListener(TodoEvent.REMOVE_COMPLETED, 
removeCompleted);            
-                       (_strand as 
IEventDispatcher).addEventListener(TodoEvent.REFRESH_LIST, refreshList);        
    
-                       (_strand as 
IEventDispatcher).addEventListener(TodoEvent.ITEM_STATE_CHANGED, 
itemStateChangedHandler);            
-                       (_strand as 
IEventDispatcher).addEventListener(TodoEvent.ITEM_LABEL_CHANGED, 
itemLabelChangedHandler);            
-                       (_strand as 
IEventDispatcher).addEventListener(TodoEvent.ITEM_REMOVED, itemRemovedHandler); 
           
+               override public function set strand(value:IStrand):void {
+                       super.strand = value;
+
+                       listenOnStrand(TodoEvent.ADD_TODO_ITEM, addTodoItem);   
         
+                       listenOnStrand(TodoEvent.TOGGLE_ALL_COMPLETE, 
toggleAllComplete);            
+                       listenOnStrand(TodoEvent.REMOVE_COMPLETED, 
removeCompleted);            
+                       listenOnStrand(TodoEvent.REFRESH_LIST, refreshList);    
        
+                       listenOnStrand(TodoEvent.ITEM_STATE_CHANGED, 
itemStateChangedHandler);            
+                       listenOnStrand(TodoEvent.ITEM_LABEL_CHANGED, 
itemLabelChangedHandler);            
+                       listenOnStrand(TodoEvent.ITEM_REMOVED, 
itemRemovedHandler);            
                        
                model = _strand.getBeadByType(IBeadModel) as TodoModel;
                        
@@ -76,17 +76,6 @@ package jewel.todomvc.controllers
                 *  Common todo model
                 */
                private var model:TodoModel;
-               
-        /**
-         *  Saves the actual data to the local storage via Local SharedObject
-         */
-        protected function saveDataToLocal():void {
-                       try {
-                               model.setItemStore(model.allItems.source);
-                       } catch (error:Error) {
-                               trace("You need to be online to store locally");
-                       }
-               }
 
         /**
          *  Add the todo item to the list, save data and refresh the list 
state 
@@ -97,8 +86,6 @@ package jewel.todomvc.controllers
                        saveDataToLocal();
                        updateInterface();
         }
-        
-
 
                /**
          *  Mark all todo items as completed or uncompleted, save data and 
update the interface accordingly
@@ -145,28 +132,6 @@ package jewel.todomvc.controllers
                                setListState();
                        }
                }
-               
-
-               /**
-                *  Sets the new state filter and refresh list to match the 
filter
-                */
-        protected function setListState():void {
-                       // setting to the same collection must cause refreshed 
too
-                       model.listItems = null;
-
-                       model.activeItems.refresh();
-                       model.completedItems.refresh();
-
-                       if(model.filterState == TodoModel.ALL_FILTER) {
-                               model.listItems = model.allItems;
-                       } 
-                       else if(model.filterState == TodoModel.ACTIVE_FILTER) {
-                               model.listItems = model.activeItems;
-                       }
-                       else if(model.filterState == 
TodoModel.COMPLETED_FILTER) {
-                               model.listItems = model.completedItems;
-                       }
-               }
 
                /**
                 *  When some todo item change state (done/undone), we must 
save data and update the interface accordingly
@@ -207,6 +172,17 @@ package jewel.todomvc.controllers
                }
 
                /**
+         *  Saves the actual data to the local storage via Local SharedObject
+         */
+        protected function saveDataToLocal():void {
+                       try {
+                               model.setItemStore(model.allItems.source);
+                       } catch (error:Error) {
+                               trace("You need to be online to store locally");
+                       }
+               }
+
+               /**
                 *  Update the interface accordingly
                 */
                public function updateInterface():void {
@@ -218,5 +194,26 @@ package jewel.todomvc.controllers
                        model.toogleAllVisibility = model.allItems.length != 0;
                        model.toggleAllToCompletedState = 
model.activeItems.length == 0;
         }
+
+               /**
+                *  Sets the new state filter and refresh list to match the 
filter
+                */
+        protected function setListState():void {
+                       // setting to the same collection must cause refreshed 
too
+                       model.listItems = null;
+
+                       model.activeItems.refresh();
+                       model.completedItems.refresh();
+
+                       if(model.filterState == TodoModel.ALL_FILTER) {
+                               model.listItems = model.allItems;
+                       } 
+                       else if(model.filterState == TodoModel.ACTIVE_FILTER) {
+                               model.listItems = model.activeItems;
+                       }
+                       else if(model.filterState == 
TodoModel.COMPLETED_FILTER) {
+                               model.listItems = model.completedItems;
+                       }
+               }
        }
 }
diff --git 
a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/events/TodoEvent.as 
b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/events/TodoEvent.as
index af37aa6..ac5fa36 100644
--- a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/events/TodoEvent.as
+++ b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/events/TodoEvent.as
@@ -34,7 +34,6 @@ package jewel.todomvc.events
                public static const TOGGLE_ALL_COMPLETE:String = 
"toggle_all_complete";
                public static const REMOVE_COMPLETED:String = 
"remove_completed";
                public static const REFRESH_LIST:String = "refresh_list";
-
                public static const ITEM_STATE_CHANGED:String = 
"item_state_changed";
                public static const ITEM_LABEL_CHANGED:String = 
"item_label_changed";
                public static const ITEM_REMOVED:String = "item_removed";
@@ -56,6 +55,8 @@ package jewel.todomvc.events
 
         /**
          * constructor
+                * 
+                * event need to bubble up to be catched for the views
          */
                public function TodoEvent(type:String, todo:TodoVO = null, 
label:String = null, completion:Boolean = false) {
                        super(type, true);
diff --git 
a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/models/TodoModel.as 
b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/models/TodoModel.as
index ed21421..1fc2a41 100644
--- a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/models/TodoModel.as
+++ b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/models/TodoModel.as
@@ -25,7 +25,6 @@ package jewel.todomvc.models
        import org.apache.royale.core.IBeadModel;
        import org.apache.royale.core.IStrand;
        import org.apache.royale.events.EventDispatcher;
-       import org.apache.royale.routing.Router;
        import org.apache.royale.storage.AMFStorage;
 
        [Bindable]
@@ -63,11 +62,6 @@ package jewel.todomvc.models
         }
 
         /**
-                *  The router that updates the browser navigation state.
-                */
-        public var router:Router;
-
-        /**
          * Saves the array ot items
          */
         public function setItemStore(items:Array):void
diff --git 
a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoFooter.mxml 
b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoFooter.mxml
index 0503abc..fc70186 100644
--- a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoFooter.mxml
+++ b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoFooter.mxml
@@ -29,6 +29,9 @@ limitations under the License.
             [Bindable]
             public var todoModel:TodoModel;
 
+            /**
+             * Refresh list when change state
+             */
             override public function set currentState(value:String):void {
                 super.currentState = value;
                 dispatchEvent(new TodoEvent(TodoEvent.REFRESH_LIST, null, 
value));
@@ -47,7 +50,6 @@ limitations under the License.
              */
             public function removeCompleted():void {
                 dispatchEvent(new TodoEvent(TodoEvent.REMOVE_COMPLETED));
-
                 clearCompleted.visible = false;
             }
         ]]>
diff --git 
a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoHeader.mxml 
b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoHeader.mxml
index c138031..7d9cd14 100644
--- a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoHeader.mxml
+++ b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoHeader.mxml
@@ -34,14 +34,13 @@ limitations under the License.
                        public var todoModel:TodoModel;
 
                        /**
-                        *  Signal todo item addition from main text box
+                        *  Signal todo item addition from main text box if 
text is not empty
                         */
                        private function addItem(event:Event):void {
                                if(event.target.text == "") return; 
                                var newTodo:TodoVO = new 
TodoVO(event.target.text);
-                               event.target.text = "";
-                               
                                dispatchEvent(new 
TodoEvent(TodoEvent.ADD_TODO_ITEM, newTodo));
+                               event.target.text = "";
                        }
 
                        /**
diff --git 
a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoListSection.mxml
 
b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoListSection.mxml
index 8ccf147..e1b2abb 100644
--- 
a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoListSection.mxml
+++ 
b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/views/TodoListSection.mxml
@@ -38,11 +38,13 @@ limitations under the License.
              */
             public function setUp():void {
                 todoModel = getBeadByType(IBeadModel) as TodoModel;
-                todoModel.router = router;
                 header.todoModel = todoModel;
                 footer.todoModel = todoModel;
             }
 
+            /**
+             *  Provide the appropiate browser window title
+             */
             private function getTitleLookup():Object {
                 var retVal:Object = {};
                 var states:Array = [
@@ -61,7 +63,7 @@ limitations under the License.
 
     <j:beads>
         <js:ContainerDataBinding/>
-        <js:Router localId="router">
+        <js:Router>
             <js:RouteToState component="{footer}"/>
             <js:RouteTitleLookup lookup="{getTitleLookup()}"/>
         </js:Router>
@@ -86,8 +88,8 @@ limitations under the License.
             </j:List>
         </html:Section>
         
-        <html:Footer className="footer" visible="{todoModel.footerVisibility}" 
currentState="All">
-            <views:TodoFooter localId="footer"/>
+        <html:Footer className="footer" visible="{todoModel.footerVisibility}">
+            <views:TodoFooter localId="footer" currentState="All"/>
         </html:Footer>
     </html:Section>
     

Reply via email to