This is an automated email from the ASF dual-hosted git repository. harbs pushed a commit to branch feature/router in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit bf72c82671ed5250c5ee8a070015ff862342fb8d Author: Harbs <ha...@in-tools.com> AuthorDate: Sun Feb 2 00:31:37 2020 +0200 Should work but the states of the buttons are messed up --- examples/jewel/todomvc/asconfig.json | 2 +- .../jewel/todomvc/controllers/TodoController.as | 39 ++++------------- .../main/royale/jewel/todomvc/events/TodoEvent.as | 1 - .../main/royale/jewel/todomvc/models/TodoModel.as | 26 ++++++++++- .../jewel/todomvc/renderers/TodoItemRenderer.mxml | 8 ++-- .../royale/jewel/todomvc/views/TodoFooter.mxml | 50 ++++++---------------- .../jewel/todomvc/views/TodoListSection.mxml | 36 +++++++--------- 7 files changed, 66 insertions(+), 96 deletions(-) diff --git a/examples/jewel/todomvc/asconfig.json b/examples/jewel/todomvc/asconfig.json index 4b6259e..14ab179 100644 --- a/examples/jewel/todomvc/asconfig.json +++ b/examples/jewel/todomvc/asconfig.json @@ -20,7 +20,7 @@ "config": "royale", "compilerOptions": { "debug": false, - "targets": ["JSRoyale","SWF"], + "targets": ["JSRoyale"], "source-map": true }, "additionalOptions": "-remove-circulars -js-output-optimization=skipAsCoercions", 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 304f64f..f63d397 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 @@ -54,23 +54,18 @@ package jewel.todomvc.controllers */ public function set strand(value:IStrand):void { _strand = value; - IEventDispatcher(_strand).addEventListener(TodoEvent.ADD_TODO_ITEM, addTodoItem); - IEventDispatcher(_strand).addEventListener(TodoEvent.TOGGLE_ALL_COMPLETE, toggleAllComplete); - IEventDispatcher(_strand).addEventListener(TodoEvent.REMOVE_COMPLETED, removeCompleted); - IEventDispatcher(_strand).addEventListener(TodoEvent.REFRESH_LIST, refreshList); - IEventDispatcher(_strand).addEventListener(TodoEvent.REFRESH_LIST_BY_USER, refreshListByUser); - IEventDispatcher(_strand).addEventListener(TodoEvent.ITEM_STATE_CHANGED, itemStateChangedHandler); - IEventDispatcher(_strand).addEventListener(TodoEvent.ITEM_LABEL_CHANGED, itemLabelChangedHandler); - IEventDispatcher(_strand).addEventListener(TodoEvent.ITEM_REMOVED, itemRemovedHandler); + (_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); model = _strand.getBeadByType(IBeadModel) as TodoModel; // retrieve local items and use it if exists - var localAllItems:Array = model.storage.data["items"]; - if(localAllItems) - model.allItems = new ArrayList(localAllItems); - else - model.allItems = new ArrayList(); + model.allItems = new ArrayList(model.getItemStore()); model.setUpFilteredCollections(); model.listItems = model.allItems; @@ -88,8 +83,7 @@ package jewel.todomvc.controllers */ protected function saveDataToLocal():void { try { - model.storage.data["items"] = model.allItems.source; - model.storage.flush(); + model.setItemStore(model.allItems.source); } catch (error:Error) { trace("You need to be online to store locally"); } @@ -153,21 +147,6 @@ package jewel.todomvc.controllers } } - /** - * Refresh the todo list to the appropiate filter state (All, Active or Completed) - */ - protected function refreshListByUser(event:TodoEvent):void - { - if(model.filterState != event.label) { - model.filterState = event.label; - - model.router.routeState.title = "TodoMVC - " + model.filterState + " State"; - model.router.routeState.state = model.filterState; - model.router.setState(); - - setListState(); - } - } /** * Sets the new state filter and refresh list to match the filter 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 1c4ba4e..af37aa6 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 REFRESH_LIST_BY_USER:String = "refresh_list_by_user"; public static const ITEM_STATE_CHANGED:String = "item_state_changed"; public static const ITEM_LABEL_CHANGED:String = "item_label_changed"; 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 79ddef6..a440eb4 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 @@ -20,7 +20,6 @@ package jewel.todomvc.models { import jewel.todomvc.vos.TodoVO; - import mx.net.SharedObject; import org.apache.royale.collections.ArrayList; import org.apache.royale.collections.ArrayListView; @@ -28,6 +27,7 @@ package jewel.todomvc.models import org.apache.royale.core.IStrand; import org.apache.royale.events.EventDispatcher; import org.apache.royale.routing.Router; + import org.apache.royale.storage.LocalStorage; [Bindable] /** @@ -69,9 +69,31 @@ package jewel.todomvc.models public var router:Router; /** + * Saves the array ot items + */ + public function setItemStore(items:Array):void + { + var itemStr:String = JSON.stringify(items); + storage.setItem("todomvc",itemStr); + } + public function getItemStore():Array + { + var itemArr:Array = []; + var itemStr:String = storage.getItem("todomvc") as String; + if(itemStr) + { + try{ + itemArr = JSON.parse(itemStr) as Array; + }catch(err:Error){ + return []; + } + } + return itemArr; + } + /** * Local storage for the todo items */ - public var storage:SharedObject = SharedObject.getLocal("todomvc"); + private var storage:LocalStorage = new LocalStorage();// SharedObject.getLocal("todomvc"); /** * the list of items binded to the todo list component diff --git a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/renderers/TodoItemRenderer.mxml b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/renderers/TodoItemRenderer.mxml index 325215b..152a0be 100644 --- a/examples/jewel/todomvc/src/main/royale/jewel/todomvc/renderers/TodoItemRenderer.mxml +++ b/examples/jewel/todomvc/src/main/royale/jewel/todomvc/renderers/TodoItemRenderer.mxml @@ -56,7 +56,7 @@ limitations under the License. /** * Destroy this todo item */ - public function removeItemClickHandler(event:MouseEvent):void { + public function removeItemClickHandler(event:Event):void { COMPILE::JS { document.removeEventListener('click', commitLabelChanges, true); @@ -74,7 +74,7 @@ limitations under the License. /** * Change renderer state to edit mode by double clicking in the todo item label */ - public function goToEditMode(event:MouseEvent):void + public function goToEditMode(event:Event):void { editfield.text = description.text; currentState = "editing"; @@ -107,7 +107,7 @@ limitations under the License. /** * Show destroy button when user rolls over the renderer */ - public function rollOverHandler(event:MouseEvent):void + public function rollOverHandler(event:Event):void { mouseIsOverRenderer = true; if(currentState == "normal") @@ -117,7 +117,7 @@ limitations under the License. /** * Hide destroy button when user rolls out the renderer */ - public function rollOutHandler(event:MouseEvent):void + public function rollOutHandler(event:Event):void { mouseIsOverRenderer = false; if(currentState == "normal") 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 0423f1c..8a395ab 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,45 +29,18 @@ limitations under the License. [Bindable] public var todoModel:TodoModel; - /** - * Used for routing. Select the appropiate state for the URL hash - */ - public function selectState(hash:String):void { - if(hash == all_btn.text) - all_btn.selected = true; - else if(hash == active_btn.text) - active_btn.selected = true; - else if(hash == completed_btn.text) - completed_btn.selected = true; - - updateToggles(hash); - dispatchEvent(new TodoEvent(TodoEvent.REFRESH_LIST, null, hash)); + override public function set currentState(value:String):void + { + super.currentState = value; + dispatchEvent(new TodoEvent(TodoEvent.REFRESH_LIST, null, value)); } /** * All toggle buttons use this handler to navigate todo list */ public function toggleButtonClickHandler(event:Event):void { - updateToggles(event.target.text); - dispatchEvent(new TodoEvent(TodoEvent.REFRESH_LIST_BY_USER, null, event.target.text)); - } - - /** - * Update toggle buttons to appropiate state - */ - public function updateToggles(label:String):void { - if(label == TodoModel.ALL_FILTER) { - active_btn.selected = false; - completed_btn.selected = false; - } - else if(label == TodoModel.ACTIVE_FILTER) { - all_btn.selected = false; - completed_btn.selected = false; - } - else if(label == TodoModel.COMPLETED_FILTER) { - all_btn.selected = false; - active_btn.selected = false; - } + event.target.selected = true; + currentState = event.target.text; } /** @@ -81,9 +54,12 @@ limitations under the License. ]]> </fx:Script> <j:states> - <js:State /> + <js:State name="All"/> + <js:State name="Active"/> + <js:State name="Completed"/> </j:states> <j:beads> + <js:SimpleStatesImpl/> <js:ContainerDataBinding/> </j:beads> @@ -92,9 +68,9 @@ limitations under the License. </j:BarSection> <j:BarSection gap="3" itemsHorizontalAlign="itemsCenter"> - <j:ToggleButton localId="all_btn" text="All" click="toggleButtonClickHandler(event)"/> - <j:ToggleButton localId="active_btn" text="Active" click="toggleButtonClickHandler(event)"/> - <j:ToggleButton localId="completed_btn" text="Completed" click="toggleButtonClickHandler(event)"/> + <j:ToggleButton localId="all_btn" selected="false" selected.All="true" text="All" click="toggleButtonClickHandler(event)"/> + <j:ToggleButton localId="active_btn" selected="false" selected.Active="true" text="Active" click="toggleButtonClickHandler(event)"/> + <j:ToggleButton localId="completed_btn" selected="false" selected.Completed="true" text="Completed" click="toggleButtonClickHandler(event)"/> </j:BarSection> <j:BarSection width="15%" gap="3" itemsHorizontalAlign="itemsRight"> 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 50ab3ec..58a20e9 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 @@ -43,35 +43,29 @@ limitations under the License. todoModel.router = router; header.todoModel = todoModel; footer.todoModel = todoModel; - - updateRouting(); } - /** - * Used for routing. If we have a routing state navigate using that info - * In other case (initial state) set to no filters (ALL_FILTER) - */ - private function updateRouting():void { - var routeState:RouteState = router.routeState; - if(routeState.state) - footer.selectState(routeState.state); - else - footer.selectState(TodoModel.ALL_FILTER); - } - - /** - * Router used this handler when the URL hash change to update app state - */ - private function hashChanged():void{ - updateRouting(); + private function getTitleLookup():Object{ + var retVal:Object = {}; + var states:Array = [ + TodoModel.ALL_FILTER, + TodoModel.ACTIVE_FILTER, + TodoModel.COMPLETED_FILTER + ] + for(var i:int=0;i<states.length;i++) + { + retVal[states[i]] = "TodoMVC - " + states[i] + " State"; + } + return retVal; } ]]> </fx:Script> <j:beads> <js:ContainerDataBinding/> - <js:Router localId="router" stateChange="hashChanged()"> + <js:Router localId="router"> <js:RouteToState component="{footer}"/> + <js:RouteTitleLookup lookup="{getTitleLookup()}"/> </js:Router> </j:beads> @@ -94,7 +88,7 @@ limitations under the License. </j:List> </html:Section> - <html:Footer className="footer" visible="{todoModel.footerVisibility}"> + <html:Footer className="footer" visible="{todoModel.footerVisibility}" currentState="All"> <views:TodoFooter localId="footer"/> </html:Footer> </html:Section>