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 2b1b15caef09e43b2f3a499c038e0e6bb1e3e5f2 Author: Harbs <[email protected]> AuthorDate: Sat Feb 1 19:51:38 2020 +0200 work on states --- .../royale/jewel/todomvc/views/TodoFooter.mxml | 4 ++- .../jewel/todomvc/views/TodoListSection.mxml | 4 ++- .../org/apache/royale/routing/RouteTitleLookup.as | 39 ++++++++++++++++++++++ .../org/apache/royale/routing/RouteToState.as | 29 +++++++++++++--- .../org/apache/royale/routing/SetRouteTitle.as | 4 +-- 5 files changed, 72 insertions(+), 8 deletions(-) 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 71756ae..0423f1c 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 @@ -80,7 +80,9 @@ limitations under the License. } ]]> </fx:Script> - + <j:states> + <js:State /> + </j:states> <j:beads> <js:ContainerDataBinding/> </j:beads> 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 47e5b8f..50ab3ec 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 @@ -70,7 +70,9 @@ limitations under the License. <j:beads> <js:ContainerDataBinding/> - <js:Router localId="router" stateChange="hashChanged()" /> + <js:Router localId="router" stateChange="hashChanged()"> + <js:RouteToState component="{footer}"/> + </js:Router> </j:beads> <html:Section className="todoapp"> diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/RouteTitleLookup.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/RouteTitleLookup.as new file mode 100644 index 0000000..d41986b --- /dev/null +++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/RouteTitleLookup.as @@ -0,0 +1,39 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.royale.routing +{ + public class RouteTitleLookup extends SetRouteTitle + { + public function RouteTitleLookup() + { + super(); + lookup = {}; + } + public var lookup:Object; + override protected function handleStateSet():void + { + var baseName:String = host.routeState.getBaseName(); + if(lookup[baseName]) + host.routeState.title = lookup[baseName]; + super.handleStateSet(); + + } + + } +} \ No newline at end of file diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/RouteToState.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/RouteToState.as index df4ef7c..cbe9d96 100644 --- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/RouteToState.as +++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/RouteToState.as @@ -52,8 +52,14 @@ package org.apache.royale.routing */ private function attachStateEvent():void { - assert(host.host is IStatesObject,"syncState can only be used on IStatesObjects"); - (host.host as IStatesObject).addEventListener("currentStateChange",handleStateChange); + var statesObject:IStatesObject = component; + if(!statesObject) + { + assert(host.host is IStatesObject,"syncState can only be used on IStatesObjects"); + statesObject = host.host as IStatesObject; + + } + statesObject.addEventListener("currentStateChange",handleStateChange); } private function handleStateChange():void @@ -61,7 +67,13 @@ package org.apache.royale.routing if(settingState)// don't do anything if the event was fired as a result of a hash. return; //TODO what about a parent path - host.routeState.path = (host.host as IStatesObject).currentState; + var statesObject:IStatesObject = component; + if(!statesObject) + { + statesObject = host.host as IStatesObject; + } + + host.routeState.path = statesObject.currentState; host.setState(); } private function hashNeeded(ev:ValueEvent):void @@ -107,13 +119,22 @@ package org.apache.royale.routing */ private function stateChanged(ev:ValueEvent):void { + var statesObject:IStatesObject = component; + if(!statesObject) + { assert(host.host is IStatesObject,"syncState can only be used on IStatesObjects"); + statesObject = host.host as IStatesObject; + } settingState = true; //TODO what about using the base name of the path? - (host.host as IStatesObject).currentState = host.routeState.path; + statesObject.currentState = host.routeState.path; settingState = false; } + /** + * The component whose state we sync. (Defaults to the strand of the router.) + */ + public var component:IStatesObject; } } \ No newline at end of file diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/SetRouteTitle.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/SetRouteTitle.as index 5320973..cd2b222 100644 --- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/SetRouteTitle.as +++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/SetRouteTitle.as @@ -31,7 +31,7 @@ package org.apache.royale.routing /** * @royaleignorecoercion org.apache.royale.routing.Router */ - private function get host():Router{ + protected function get host():Router{ return _strand as Router } @@ -61,7 +61,7 @@ package org.apache.royale.routing } } - private function handleStateSet():void + protected function handleStateSet():void { COMPILE::JS {
