You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by pi...@apache.org on 2020/04/17 09:11:39 UTC
[royale-asjs] branch develop updated: Router: Make onInit protected
to give more opportunity to extend it
This is an automated email from the ASF dual-hosted git repository.
piotrz 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 d978539 Router: Make onInit protected to give more opportunity to extend it
d978539 is described below
commit d9785391cf96243c5fd6132847288fd2b82d06ff
Author: Piotr Zarzycki <pi...@gmail.com>
AuthorDate: Fri Apr 17 11:10:35 2020 +0200
Router: Make onInit protected to give more opportunity to extend it
---
.../royale/org/apache/royale/routing/Router.as | 210 +++++++++++----------
1 file changed, 108 insertions(+), 102 deletions(-)
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/Router.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/Router.as
index 08df81b..1304f61 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/Router.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/routing/Router.as
@@ -63,128 +63,134 @@ package org.apache.royale.routing
*/
public class Router extends Strand implements IBead, IMXMLDocument
{
- public function Router()
- {
-
- }
- public function get host():IStrand
- {
- return _strand;
- }
- private var _strand:IStrand;
+ public function Router()
+ {
+
+ }
+
+ public function get host():IStrand
+ {
+ return _strand;
+ }
+
+ private var _strand:IStrand;
public function set strand(value:IStrand):void
{
_strand = value;
- loadBeadFromValuesManager(IPathRouteBead, "iPathRouteBead", this);
+ loadBeadFromValuesManager(IPathRouteBead, "iPathRouteBead", this);
COMPILE::JS
{
window.addEventListener("hashchange", hashChangeHandler);
}
- // wait until the app is initialized. Calling onInit async soves this problem
- callLater(onInit);
+ // wait until the app is initialized. Calling onInit async soves this problem
+ callLater(onInit);
}
- /**
- * Helper function to attach event listener without the need for casting
- * @royaleignorecoercion org.apache.royale.events.IEventDispatcher
- */
- protected function listenOnStrand(eventType:String,handler:Function,capture:Boolean=false):void
- {
- (_strand as IEventDispatcher).addEventListener(eventType, handler, capture);
- }
- private function onInit(event:Event):void
- {
- if(beads)
- {
- for each (var bead:IBead in beads)
- addBead(bead);
- }
- // needed for binding in MXML
- dispatchEvent(new Event("initBindings"));
-
- COMPILE::JS
- {
- if(location.hash)
+
+ /**
+ * Helper function to attach event listener without the need for casting
+ * @royaleignorecoercion org.apache.royale.events.IEventDispatcher
+ */
+ protected function listenOnStrand(eventType:String,handler:Function,capture:Boolean=false):void
{
- hashChangeHandler();
+ (_strand as IEventDispatcher).addEventListener(eventType, handler, capture);
}
- else// if there's no hash we should still dispatch a stateChange event so the beads can set defaults
+
+ protected function onInit(event:Event):void
{
- dispatchEvent(new Event("stateChange"));
+ if(beads)
+ {
+ for each (var bead:IBead in beads)
+ addBead(bead);
+ }
+ // needed for binding in MXML
+ dispatchEvent(new Event("initBindings"));
+
+ COMPILE::JS
+ {
+ if(location.hash)
+ {
+ hashChangeHandler();
+ }
+ else// if there's no hash we should still dispatch a stateChange event so the beads can set defaults
+ {
+ dispatchEvent(new Event("stateChange"));
+ }
+ }
}
- }
- }
+
private function hashChangeHandler():void
{
- parseHash();
+ parseHash();
dispatchEvent(new Event("stateChange"));
}
- private function parseHash():void
- {
- //TODO SWF implementation
- COMPILE::JS
- {
- var hash:String = location.hash;
- var index:int = 0;
- if(hash.indexOf("!")==1){
- index = 1;
+
+ private function parseHash():void
+ {
+ //TODO SWF implementation
+ COMPILE::JS
+ {
+ var hash:String = location.hash;
+ var index:int = 0;
+ if(hash.indexOf("!")==1){
+ index = 1;
+ }
+ hash = hash.slice(index+1);
+ var ev:ValueEvent = new ValueEvent("hashReceived",hash);
+ dispatchEvent(ev);
+ }
}
- hash = hash.slice(index+1);
- var ev:ValueEvent = new ValueEvent("hashReceived",hash);
- dispatchEvent(ev);
- }
- }
-
- private var _routeState:RouteState;
-
- public function get routeState():RouteState
- {
- if(!_routeState){
- _routeState = new RouteState();
- }
- return _routeState;
- }
-
- public function set routeState(value:RouteState):void
- {
- _routeState = value;
- }
- /**
- * Commits the current state to the browsing history
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.9.7
- */
- public function setState():void
- {
- COMPILE::JS
- {
- var hash:String = "#!";
- var ev:ValueEvent = new ValueEvent("hashNeeded","");
- dispatchEvent(ev);
- var stateEv:ValueEvent = new ValueEvent("stateNeeded",{});
- dispatchEvent(stateEv);
- if(!ev.defaultPrevented)
+
+ private var _routeState:RouteState;
+
+ public function get routeState():RouteState
{
- hash += ev.value;
- window.history.pushState(stateEv.value,_routeState.title,hash);
- sendStrandEvent(this,"stateSet");
+ if(!_routeState){
+ _routeState = new RouteState();
+ }
+ return _routeState;
+ }
+
+ public function set routeState(value:RouteState):void
+ {
+ _routeState = value;
+ }
+ /**
+ * Commits the current state to the browsing history
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.7
+ */
+ public function setState():void
+ {
+ COMPILE::JS
+ {
+ var hash:String = "#!";
+ var ev:ValueEvent = new ValueEvent("hashNeeded","");
+ dispatchEvent(ev);
+ var stateEv:ValueEvent = new ValueEvent("stateNeeded",{});
+ dispatchEvent(stateEv);
+ if(!ev.defaultPrevented)
+ {
+ hash += ev.value;
+ window.history.pushState(stateEv.value,_routeState.title,hash);
+ sendStrandEvent(this,"stateSet");
+ }
+ }
+ }
+ /**
+ * Same as setState, but also notifies of the state change
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.7
+ */
+ public function renderState():void
+ {
+ setState();
+ dispatchEvent(new Event("stateChange"));
}
- }
- }
- /**
- * Same as setState, but also notifies of the state change
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.9.7
- */
- public function renderState():void
- {
- setState();
- dispatchEvent(new Event("stateChange"));
- }
private var _mxmlDescriptor:Array;
private var _mxmlDocument:Object = this;