add newInstance to reduce use of 'Class' when cross-compiling

Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c244e29a
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c244e29a
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c244e29a

Branch: refs/heads/develop
Commit: c244e29a8392feb6ef035353c804607517f3bfbb
Parents: 3e1a12c
Author: Alex Harui <aha...@apache.org>
Authored: Sat May 24 08:41:27 2014 -0700
Committer: Alex Harui <aha...@apache.org>
Committed: Sat May 24 08:41:27 2014 -0700

----------------------------------------------------------------------
 .../src/org/apache/flex/core/IValuesImpl.as     | 20 +++++++++++++++++++-
 .../org/apache/flex/core/SimpleCSSValuesImpl.as | 16 ++++++++++++++++
 .../org/apache/flex/core/SimpleValuesImpl.as    | 16 ++++++++++++++++
 .../src/org/apache/flex/core/IValuesImpl.js     | 13 +++++++++++++
 .../org/apache/flex/core/SimpleCSSValuesImpl.js | 17 +++++++++++++++++
 5 files changed, 81 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c244e29a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IValuesImpl.as
----------------------------------------------------------------------
diff --git 
a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IValuesImpl.as 
b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IValuesImpl.as
index 382597f..239c52f 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IValuesImpl.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IValuesImpl.as
@@ -49,7 +49,25 @@ package org.apache.flex.core
          */
                function getValue(thisObject:Object, valueName:String, 
state:String = null, attrs:Object = null):*;
 
-        /**
+               /**
+                *  Returns a new instance based on the value for a given 
object based on a property name,
+                *  and optionally, the current state, and a set of property 
value pairs.  This is a way
+                *  to avoid using the Class type in AS code.
+                *
+                *  @param thisObject The object to get the value for.
+                *  @param valueName The name of a property. e.g. fontFamily, 
color, etc.
+                *  @param state The name of a state. e.g. hovered, visited
+                *  @param attrs A map of property value pairs that may affect 
the returned value.
+                *  @return A value or undefined
+                * 
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               function newInstance(thisObject:Object, valueName:String, 
state:String = null, attrs:Object = null):*;
+
+               /**
          *  Returns a shared instance, instantiating the shared instance if
          *  it doesn't exist.  Often used to share "managers"
          *

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c244e29a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleCSSValuesImpl.as
----------------------------------------------------------------------
diff --git 
a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleCSSValuesImpl.as
 
b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleCSSValuesImpl.as
index f454c2f..81d5506 100644
--- 
a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleCSSValuesImpl.as
+++ 
b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleCSSValuesImpl.as
@@ -365,6 +365,22 @@ package org.apache.flex.core
                        }
                }
         
+               /**
+                *  @copy org.apache.flex.core.IValuesImpl#newInstance()
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               public function newInstance(thisObject:Object, 
valueName:String, state:String = null, attrs:Object = null):*
+               {
+                       var c:Class = getValue(thisObject, valueName, state, 
attrs);
+                       if (c)
+                               return new c();
+                       return null;
+               }
+               
         /**
          *  @copy org.apache.flex.core.IValuesImpl#getInstance()
          *  

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c244e29a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleValuesImpl.as
----------------------------------------------------------------------
diff --git 
a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleValuesImpl.as 
b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleValuesImpl.as
index 8e04a7e..41b55db 100644
--- 
a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleValuesImpl.as
+++ 
b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleValuesImpl.as
@@ -63,6 +63,22 @@ package org.apache.flex.core
                        return values[valueName];
                }
                
+               /**
+                *  @copy org.apache.flex.core.IValuesImpl#newInstance()
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               public function newInstance(thisObject:Object, 
valueName:String, state:String = null, attrs:Object = null):*
+               {
+                       var c:Class = values[valueName];
+                       if (c)
+                               return new c();
+                       return null;
+               }
+               
         /**
          *  A method that stores a value to be shared with other objects.
          *  It is global, not per instance.  Fancier implementations

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c244e29a/frameworks/js/FlexJS/src/org/apache/flex/core/IValuesImpl.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/core/IValuesImpl.js 
b/frameworks/js/FlexJS/src/org/apache/flex/core/IValuesImpl.js
index e0b77ae..fa1e9d4 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/core/IValuesImpl.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/core/IValuesImpl.js
@@ -55,6 +55,19 @@ org.apache.flex.core.IValuesImpl.prototype.getValue =
 
 /**
  * @expose
+ * @param {Object} thisObject The object to fetch a value for.
+ * @param {string} valueName The name of the value to fetch.
+ * @param {string=} opt_state The psuedo-state if any for.
+ * @param {Object=} opt_attrs The object with name value pairs that
+ *                       might make a difference.
+ * @return {Object} The new instance.
+ */
+org.apache.flex.core.IValuesImpl.prototype.newInstance =
+function(thisObject, valueName, opt_state, opt_attrs) {};
+
+
+/**
+ * @expose
  * @param {Object} mainclass The main class for the application.
  */
 org.apache.flex.core.IValuesImpl.prototype.init = function(mainclass) {};

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c244e29a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js
----------------------------------------------------------------------
diff --git 
a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js 
b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js
index a420c6f..d75663d 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleCSSValuesImpl.js
@@ -153,6 +153,23 @@ 
org.apache.flex.core.SimpleCSSValuesImpl.prototype.getValue =
 
 
 /**
+ * @param {Object} thisObject The object to fetch a value for.
+ * @param {string} valueName The name of the value to fetch.
+ * @param {string=} opt_state The psuedo-state if any for.
+ * @param {Object=} opt_attrs The object with name value pairs that
+ *                       might make a difference.
+ * @return {Object} The value.
+ */
+org.apache.flex.core.SimpleCSSValuesImpl.prototype.newInstance =
+function(thisObject, valueName, opt_state, opt_attrs) {
+  var f = this.getValue(thisObject, valueName, opt_state, opt_attrs);
+  if (f)
+    return new f();
+  return null;
+};
+
+
+/**
  * @param {Object} mainclass The main class for the application.
  */
 org.apache.flex.core.SimpleCSSValuesImpl.prototype.init = function(mainclass) {

Reply via email to