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 ba75339  crux: helper for easier use
ba75339 is described below

commit ba75339cfdb03042473bdd04253b5916754570d1
Author: Carlos Rovira <[email protected]>
AuthorDate: Fri Sep 25 20:05:59 2020 +0200

    crux: helper for easier use
---
 .../Crux/src/main/resources/crux-manifest.xml      |   1 +
 .../main/royale/org/apache/royale/crux/ICrux.as    |   3 +-
 .../org/apache/royale/crux/beads/CruxHelper.as     | 181 +++++++++++++++++++++
 .../org/apache/royale/crux/utils/buildCrux.as      |  58 +++++++
 4 files changed, 242 insertions(+), 1 deletion(-)

diff --git a/frameworks/projects/Crux/src/main/resources/crux-manifest.xml 
b/frameworks/projects/Crux/src/main/resources/crux-manifest.xml
index b54971b..6b55c07 100644
--- a/frameworks/projects/Crux/src/main/resources/crux-manifest.xml
+++ b/frameworks/projects/Crux/src/main/resources/crux-manifest.xml
@@ -25,4 +25,5 @@
     <component id="AMFStorageBean" 
class="org.apache.royale.crux.storage.AMFStorageBean"/>
 
     <component id="JSStageEvents" 
class="org.apache.royale.crux.beads.JSStageEvents"/>
+    <component id="CruxHelper" 
class="org.apache.royale.crux.beads.CruxHelper"/>
 </componentPackage>
diff --git 
a/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/ICrux.as 
b/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/ICrux.as
index 03e624e..3240a58 100644
--- a/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/ICrux.as
+++ b/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/ICrux.as
@@ -16,11 +16,12 @@
 package org.apache.royale.crux
 {
     import org.apache.royale.events.IEventDispatcher;
+    import org.apache.royale.core.IBead;
 
     /**
         * ICrux Interface
         */
-       public interface ICrux
+       public interface ICrux extends IBead
        {
                /**
                 * whether or not to process views
diff --git 
a/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/beads/CruxHelper.as
 
b/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/beads/CruxHelper.as
new file mode 100644
index 0000000..9e75328
--- /dev/null
+++ 
b/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/beads/CruxHelper.as
@@ -0,0 +1,181 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.crux.beads
+{
+    import org.apache.royale.core.ApplicationBase;
+    import org.apache.royale.core.IBead;
+    import org.apache.royale.core.IStrand;
+    import org.apache.royale.crux.ICrux;
+    import org.apache.royale.crux.utils.buildCrux;
+    import org.apache.royale.events.IEventDispatcher;
+    
+    /**
+     *  CruxHelper generate a Crux for an Application or a Module
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9.8
+     */
+    public class CruxHelper implements IBead
+    {
+        public function CruxHelper() {
+                       super();
+               }
+
+        private var host:IEventDispatcher;
+        /**
+         *  @copy org.apache.royale.core.IBead#strand
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         *
+         *  @royaleignorecoercion org.apache.royale.core.ElementWrapper
+         *  @royaleignorecoercion org.apache.royale.events.IEventDispatcher
+         */
+        public function set strand(value:IStrand):void
+        {
+            host = value as IEventDispatcher;
+
+            if(host is ApplicationBase)
+            {
+                var jsStageEvents:JSStageEvents = new JSStageEvents();
+                jsStageEvents.packageExclusionFilter = _packageExclusionFilter;
+                value.addBead(jsStageEvents);
+            }
+
+            crux = buildCrux(host, beanProviders, eventPackages, viewPackages);
+            
+            if(parentCrux)
+                crux.parentCrux = parentCrux;
+
+            value.addBead(crux);
+        }
+
+        private var _crux:ICrux;
+        /**
+         *  The generated crux instance
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function get crux():ICrux
+        {
+               return _crux;
+        }
+        public function set crux(value:ICrux):void
+        {
+               _crux = value;
+        }
+
+        private var _beanProviders:Array;
+        /**
+         *  The Array of bean providers
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function get beanProviders():Array
+        {
+               return _beanProviders;
+        }
+        public function set beanProviders(value:*):void
+        {
+               _beanProviders = value;
+        }
+
+        private var _eventPackages:Array;
+        /**
+         *  The Array of event packages
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function get eventPackages():Array
+        {
+               return _eventPackages;
+        }
+        public function set eventPackages(value:*):void
+        {
+               _eventPackages = value;
+        }
+
+        private var _viewPackages:Array;
+        /**
+         *  The Array of view packages
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function get viewPackages():Array
+        {
+               return _viewPackages;
+        }
+        public function set viewPackages(value:*):void
+        {
+               _viewPackages = value;
+        }
+        
+        private var _packageExclusionFilter:String = "_default_";
+        /**
+         *  The package exclusion filter to use in JSStageEvents 
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function get packageExclusionFilter():String
+        {
+               return _packageExclusionFilter;
+        }
+        public function set packageExclusionFilter(value:String):void
+        {
+               _packageExclusionFilter = value;
+        }
+        
+        private var _parentCrux:ICrux;
+        /**
+         *  The parent crux 
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.8
+         */
+        public function get parentCrux():ICrux
+        {
+               return _parentCrux;
+        }
+        public function set parentCrux(value:ICrux):void
+        {
+               _parentCrux = value;
+        }
+    }
+}
\ No newline at end of file
diff --git 
a/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/utils/buildCrux.as
 
b/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/utils/buildCrux.as
new file mode 100644
index 0000000..178b581
--- /dev/null
+++ 
b/frameworks/projects/Crux/src/main/royale/org/apache/royale/crux/utils/buildCrux.as
@@ -0,0 +1,58 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.crux.utils
+{
+    import org.apache.royale.crux.BeanFactory;
+    import org.apache.royale.crux.Crux;
+    import org.apache.royale.crux.CruxConfig;
+    import org.apache.royale.crux.ICrux;
+    import org.apache.royale.crux.ICruxConfig;
+    import org.apache.royale.events.IEventDispatcher;
+
+       /**
+        *  Initialize a crux instance.
+        *
+        *  @param dispatcher The <code>IEventDispatcher</code> used for crux 
to dispatch events
+        *  @param beanProviderClasses The <code>Array</code> of classes where 
crux will get its beans
+        *  @param eventPackages The <code>Array</code> of packages where crux 
should search for events
+        *  @param viewPackages The <code>Array</code> of packages where crux 
should search for views
+        * 
+        *  @return The <code>ICrux</code> with the recently created crux 
instance.
+        */
+       public function buildCrux(dispatcher:IEventDispatcher, 
beanProviderClasses:Array, eventPackages:Array, viewPackages:Array):ICrux
+       {
+               // crux config
+               var config:ICruxConfig = new CruxConfig();
+               config.eventPackages = eventPackages ? eventPackages : new 
Array();
+               config.viewPackages = viewPackages ? viewPackages : new Array();
+               config.strict = true;
+
+               // add beans
+               var providers:Array = new Array();
+               var _beanLoaders:Array = beanProviderClasses ? 
beanProviderClasses : new Array();
+
+               var len:int = _beanLoaders.length;
+               for(var index:int = 0; index < len; index++)
+               {
+                       providers.push(_beanLoaders[index]);
+               }
+
+               return new Crux(dispatcher, config, new BeanFactory(), 
providers);
+       }
+}
\ No newline at end of file

Reply via email to