flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - An example of how API parity would look. I started at SimpleStateImpl and worked my way up ; -)
Date Thu, 07 Nov 2013 19:27:48 GMT
Updated Branches:
  refs/heads/develop 4b17f61ce -> 9fa2c6f9b


An example of how API parity would look. I started at SimpleStateImpl and worked my way up
;-)

Also, all these files now comply with the gjslint and JSHint code quality requirements.

Signed-off-by: Erik de Bruin <erik@ixsoftware.nl>


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

Branch: refs/heads/develop
Commit: 9fa2c6f9ba48b7404a873a26ca98658f1aa33e2d
Parents: 4b17f61
Author: Erik de Bruin <erik@ixsoftware.nl>
Authored: Thu Nov 7 20:27:13 2013 +0100
Committer: Erik de Bruin <erik@ixsoftware.nl>
Committed: Thu Nov 7 20:27:21 2013 +0100

----------------------------------------------------------------------
 frameworks/js/FlexJS/src/mx/states/AddItems.js  |  35 +++-
 .../js/FlexJS/src/mx/states/SetProperty.js      |  35 +++-
 frameworks/js/FlexJS/src/mx/states/State.js     |   4 +-
 .../src/org/apache/flex/core/IStatesImpl.js     |  38 +++++
 .../FlexJS/src/org/apache/flex/core/IStrand.js  |  55 ++++++
 .../org/apache/flex/core/SimpleStatesImpl.js    | 171 ++++++++++---------
 .../org/apache/flex/events/IEventDispatcher.js  |  25 +++
 7 files changed, 272 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9fa2c6f9/frameworks/js/FlexJS/src/mx/states/AddItems.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/mx/states/AddItems.js b/frameworks/js/FlexJS/src/mx/states/AddItems.js
index 6b1a347..3cf63a2 100644
--- a/frameworks/js/FlexJS/src/mx/states/AddItems.js
+++ b/frameworks/js/FlexJS/src/mx/states/AddItems.js
@@ -14,10 +14,13 @@
 
 goog.provide('mx.states.AddItems');
 
+goog.require('org.apache.flex.core.IDocument');
+
 
 
 /**
  * @constructor
+ * @implements {org.apache.flex.core.IDocument}
  */
 mx.states.AddItems = function() {
 };
@@ -25,19 +28,15 @@ mx.states.AddItems = function() {
 
 /**
  * @param {Object} document The MXML object.
+ * @param {string=} opt_id The id.
  */
-mx.states.AddItems.prototype.setDocument = function(document) {
+mx.states.AddItems.prototype.setDocument = function(document, opt_id) {
+  opt_id = typeof opt_id !== 'undefined' ? opt_id : null;
   this.document = document;
 };
 
 
 /**
- * @type {string} document The type of override.
- */
-mx.states.AddItems.prototype.type = 'AddItems';
-
-
-/**
  * @expose
  * @type {Object} document The MXML object.
  */
@@ -85,3 +84,25 @@ mx.states.AddItems.prototype.position = null;
  */
 mx.states.AddItems.prototype.relativeTo = null;
 
+
+/**
+ * @expose
+ * @param {Object} properties The properties for the new object.
+ * @return {Object} The new object.
+ */
+mx.states.AddItems.prototype.initializeFromObject = function(properties) {
+  var p;
+
+  for (p in properties) {
+    this[p] = properties[p];
+  }
+
+  return this;
+};
+
+
+/**
+ * @const
+ */
+mx.states.AddItems.prototype.FLEXJS_CLASS_INFO =
+    { interfaces: [org.apache.flex.core.IDocument] };

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9fa2c6f9/frameworks/js/FlexJS/src/mx/states/SetProperty.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/mx/states/SetProperty.js b/frameworks/js/FlexJS/src/mx/states/SetProperty.js
index 371d986..cfc8b53 100644
--- a/frameworks/js/FlexJS/src/mx/states/SetProperty.js
+++ b/frameworks/js/FlexJS/src/mx/states/SetProperty.js
@@ -14,10 +14,13 @@
 
 goog.provide('mx.states.SetProperty');
 
+goog.require('org.apache.flex.core.IDocument');
+
 
 
 /**
  * @constructor
+ * @implements {org.apache.flex.core.IDocument}
  */
 mx.states.SetProperty = function() {
 };
@@ -25,19 +28,15 @@ mx.states.SetProperty = function() {
 
 /**
  * @param {Object} document The MXML object.
+ * @param {string=} opt_id The id.
  */
-mx.states.SetProperty.prototype.setDocument = function(document) {
+mx.states.SetProperty.prototype.setDocument = function(document, opt_id) {
+  opt_id = typeof opt_id !== 'undefined' ? opt_id : null;
   this.document = document;
 };
 
 
 /**
- * @type {string} document The type of override.
- */
-mx.states.SetProperty.prototype.type = 'SetProperty';
-
-
-/**
  * @expose
  * @type {Object} document The MXML object.
  */
@@ -71,3 +70,25 @@ mx.states.SetProperty.prototype.previousValue = null;
  */
 mx.states.SetProperty.prototype.value = null;
 
+
+/**
+ * @expose
+ * @param {Object} properties The properties for the new object.
+ * @return {Object} The new object.
+ */
+mx.states.SetProperty.prototype.initializeFromObject = function(properties) {
+  var p;
+
+  for (p in properties) {
+    this[p] = properties[p];
+  }
+
+  return this;
+};
+
+
+/**
+ * @const
+ */
+mx.states.SetProperty.prototype.FLEXJS_CLASS_INFO =
+    { interfaces: [org.apache.flex.core.IDocument] };

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9fa2c6f9/frameworks/js/FlexJS/src/mx/states/State.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/mx/states/State.js b/frameworks/js/FlexJS/src/mx/states/State.js
index 29541f9..b325c50 100644
--- a/frameworks/js/FlexJS/src/mx/states/State.js
+++ b/frameworks/js/FlexJS/src/mx/states/State.js
@@ -18,8 +18,10 @@ goog.provide('mx.states.State');
 
 /**
  * @constructor
+ * @param {Object=} opt_props The initial properties.
  */
-mx.states.State = function() {
+mx.states.State = function(opt_props) {
+  opt_props = typeof opt_props !== 'undefined' ? opt_props : null;
 };
 
 

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9fa2c6f9/frameworks/js/FlexJS/src/org/apache/flex/core/IStatesImpl.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/core/IStatesImpl.js b/frameworks/js/FlexJS/src/org/apache/flex/core/IStatesImpl.js
new file mode 100644
index 0000000..ddb9ebd
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/core/IStatesImpl.js
@@ -0,0 +1,38 @@
+/**
+ * Licensed 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.
+ */
+
+goog.provide('org.apache.flex.core.IStatesImpl');
+
+goog.require('org.apache.flex.core.IBead');
+goog.require('org.apache.flex.events.IEventDispatcher');
+
+
+
+/**
+ * IStatesImpl
+ *
+ * @interface
+ * @extends {org.apache.flex.core.IBead}
+ * @extends {org.apache.flex.events.IEventDispatcher}
+ */
+org.apache.flex.core.IStatesImpl = function() {
+};
+
+
+/**
+ * @const
+ */
+org.apache.flex.core.IStatesImpl.prototype.FLEXJS_CLASS_INFO =
+    { interfaces: [org.apache.flex.core.IBead,
+                   org.apache.flex.events.IEventDispatcher] };

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9fa2c6f9/frameworks/js/FlexJS/src/org/apache/flex/core/IStrand.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/core/IStrand.js b/frameworks/js/FlexJS/src/org/apache/flex/core/IStrand.js
new file mode 100644
index 0000000..8356f12
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/core/IStrand.js
@@ -0,0 +1,55 @@
+/**
+ * Licensed 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.
+ */
+
+goog.provide('org.apache.flex.core.IStrand');
+
+
+
+/**
+ * IStrand
+ *
+ * @interface
+ */
+org.apache.flex.core.IStrand = function() {
+};
+
+
+/**
+ * addBead()
+ *
+ * @expose
+ * @param {org.apache.flex.core.IBead} bead The bead to add.
+ */
+org.apache.flex.core.IStrand.prototype.addBead = function(bead) {};
+
+
+/**
+ * getBeadByType()
+ *
+ * @expose
+ * @param {Object} classOrInterface The type of bead to look for.
+ * @return {org.apache.flex.core.IBead} The bead.
+ */
+org.apache.flex.core.IStrand.prototype.getBeadByType =
+    function(classOrInterface) {};
+
+
+/**
+ * removeBead()
+ *
+ * @expose
+ * @param {org.apache.flex.core.IBead} bead The bead to remove.
+ * @return {org.apache.flex.core.IBead} The bead that was removed.
+ */
+org.apache.flex.core.IStrand.prototype.removeBead = function(bead) {};

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9fa2c6f9/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
index e71bc8f..f0fc482 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
@@ -14,19 +14,27 @@
 
 goog.provide('org.apache.flex.core.SimpleStatesImpl');
 
+goog.require('mx.states.AddItems');
+goog.require('mx.states.SetProperty');
+goog.require('mx.states.State');
+goog.require('org.apache.flex.core.IBead');
+goog.require('org.apache.flex.core.IStatesImpl');
+goog.require('org.apache.flex.core.IStrand');
 goog.require('org.apache.flex.events.EventDispatcher');
 
 
 
 /**
  * @constructor
+ * @implements {org.apache.flex.core.IBead}
+ * @implements {org.apache.flex.core.IStatesImpl}
  */
 org.apache.flex.core.SimpleStatesImpl = function() {
   goog.base(this);
 
   /**
    * @private
-   * @type {Object}
+   * @type {org.apache.flex.core.IStrand}
    */
   this.strand_ = null;
 };
@@ -36,42 +44,40 @@ goog.inherits(org.apache.flex.core.SimpleStatesImpl,
 
 /**
  * @expose
- * @param {Object} value The new host.
+ * @param {org.apache.flex.core.IStrand} value The new host.
  */
 org.apache.flex.core.SimpleStatesImpl.prototype.set_strand =
     function(value) {
   if (this.strand_ !== value) {
     this.strand_ = value;
     this.strand_.addEventListener('currentStateChanged',
-        goog.bind(this.stateChangeHandler, this));
+        goog.bind(this.stateChangeHandler_, this));
   }
 };
 
 
 /**
- * @protected
+ * @private
  * @param {Object} event The event.
  */
-org.apache.flex.core.SimpleStatesImpl.prototype.stateChangeHandler =
+org.apache.flex.core.SimpleStatesImpl.prototype.stateChangeHandler_ =
     function(event) {
-  var s, p;
-  var doc = event.target;
-  var arr = doc.get_states();
-  for (p in arr)
-  {
+  var arr, doc, p, s;
+
+  doc = event.target;
+  arr = doc.get_states();
+  for (p in arr) {
     s = arr[p];
-    if (s.name == event.oldValue)
-    {
-      this.revert(s);
+    if (s.name === event.oldValue) {
+      this.revert_(s);
       break;
     }
   }
-  for (p in arr)
-  {
+
+  for (p in arr) {
     s = arr[p];
-    if (s.name == event.newValue)
-    {
-      this.applyState(s);
+    if (s.name === event.newValue) {
+      this.apply_(s);
       break;
     }
   }
@@ -79,109 +85,122 @@ org.apache.flex.core.SimpleStatesImpl.prototype.stateChangeHandler =
 
 
 /**
- * @protected
- * @param {Object} s The State to revert.
+ * @private
+ * @param {mx.states.State} s The State to revert.
  */
-org.apache.flex.core.SimpleStatesImpl.prototype.revert = function(s) {
-  var p, o;
-  var arr = s.overrides;
-  for (p in arr)
-  {
+org.apache.flex.core.SimpleStatesImpl.prototype.revert_ = function(s) {
+  var arr, item, o, p, parent, q, target;
+
+  arr = s.overrides;
+  for (p in arr) {
     o = arr[p];
-    if (o.type == 'AddItems')
-    {
-      for (var q in o.items)
-      {
-        var item = o.items[q];
-        var parent;
-        if (typeof(o.document['get_' + o.destination]) == 'function')
+    if (org.apache.flex.utils.Language.is(o, mx.states.AddItems)) {
+      for (q in o.items) {
+        item = o.items[q];
+
+        if (typeof(o.document['get_' + o.destination]) === 'function') {
           parent = o.document['get_' + o.destination]();
-        else
+        } else {
           parent = o.document[o.destination];
+        }
+
         parent.removeElement(item);
         parent.dispatchEvent(
             new org.apache.flex.events.Event('childrenAdded'));
       }
-    }
-    else if (o.type == 'SetProperty')
-    {
-      var target;
-      if (typeof(o.document['get_' + o.target]) == 'function')
+    } else if (org.apache.flex.utils.Language.is(o, mx.states.SetProperty)) {
+      if (typeof(o.document['get_' + o.target]) === 'function') {
         target = o.document['get_' + o.target]();
-      else
+      } else {
         target = o.document[o.target];
-      if (typeof(target['set_' + o.name]) == 'function')
+      }
+
+      if (typeof(target['set_' + o.name]) === 'function') {
         target['set_' + o.name](o.previousValue);
-      else
+      } else {
         target[o.name] = o.previousValue;
+      }
     }
   }
 };
 
 
 /**
- * @protected
- * @param {Object} s The State to apply.
+ * @private
+ * @param {mx.states.State} s The State to apply.
  */
-org.apache.flex.core.SimpleStatesImpl.prototype.applyState = function(s) {
-  var o, p;
-  var arr = s.overrides;
-  for (p in arr)
-  {
+org.apache.flex.core.SimpleStatesImpl.prototype.apply_ = function(s) {
+  var arr, child, index, item, o, p, parent, q, target;
+
+  arr = s.overrides;
+  for (p in arr) {
     o = arr[p];
-    if (o.type == 'AddItems')
-    {
-      if (o.items == null)
-      {
+    if (org.apache.flex.utils.Language.is(o, mx.states.AddItems)) {
+      if (!o.items) {
         //TODO (aharui).  This array should be deferred
         //var di = org.apache.flex.utils.MXMLDataInterpreter;
         //o.items = di.generateMXMLArray(o.document,
         //                                null, o.itemsDescriptor, true);
         o.items = o.itemsDescriptor;
       }
-      for (var q in o.items)
-      {
-        var item = o.items[q];
-        var parent;
-        if (typeof(o.document['get_' + o.destination]) == 'function')
+
+      for (q in o.items) {
+        item = o.items[q];
+
+        if (typeof(o.document['get_' + o.destination]) === 'function') {
           parent = o.document['get_' + o.destination]();
-        else
+        } else {
           parent = o.document[o.destination];
-        if (o.relativeTo != null)
-        {
-          var child;
-          if (typeof(o.document['get_' + o.relativeTo]) == 'function')
+        }
+
+        if (o.relativeTo) {
+          if (typeof(o.document['get_' + o.relativeTo]) === 'function') {
             child = o.document['get_' + o.relativeTo]();
-          else
+          } else {
             child = o.document[o.relativeTo];
-          var index = parent.getElementIndex(child);
-          if (o.position == 'after')
+          }
+
+          index = parent.getElementIndex(child);
+          if (o.position === 'after') {
             index++;
+          }
+
           parent.addElementAt(item, index);
-        }
-        else
-        {
+        } else {
           parent.addElement(item);
         }
+
         parent.dispatchEvent(
             new org.apache.flex.events.Event('childrenAdded'));
       }
     }
-    else if (o.type == 'SetProperty')
+    else if (org.apache.flex.utils.Language.is(o, mx.states.SetProperty))
     {
-      var target;
-      if (typeof(o.document['get_' + o.target]) == 'function')
+      if (typeof(o.document['get_' + o.target]) === 'function') {
         target = o.document['get_' + o.target]();
-      else
+      } else {
         target = o.document[o.target];
-      if (typeof(target['get_' + o.name]) == 'function')
+      }
+
+      if (typeof(target['get_' + o.name]) === 'function') {
         o.previousValue = target['get_' + o.name]();
-      else
+      } else {
         o.previousValue = target[o.name];
-      if (typeof(target['set_' + o.name]) == 'function')
+      }
+
+      if (typeof(target['set_' + o.name]) === 'function') {
         target['set_' + o.name](o.value);
-      else
+      } else {
         target[o.name] = o.value;
+      }
     }
   }
 };
+
+
+/**
+ * @const
+ */
+org.apache.flex.core.SimpleStatesImpl.prototype.FLEXJS_CLASS_INFO =
+    { interfaces: [org.apache.flex.core.IBead,
+                   org.apache.flex.core.IStatesImpl] };

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9fa2c6f9/frameworks/js/FlexJS/src/org/apache/flex/events/IEventDispatcher.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/events/IEventDispatcher.js b/frameworks/js/FlexJS/src/org/apache/flex/events/IEventDispatcher.js
new file mode 100644
index 0000000..401e976
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/events/IEventDispatcher.js
@@ -0,0 +1,25 @@
+/**
+ * Licensed 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.
+ */
+
+goog.provide('org.apache.flex.events.IEventDispatcher');
+
+
+
+/**
+ * IEventDispatcher
+ *
+ * @interface
+ */
+org.apache.flex.events.IEventDispatcher = function() {
+};


Mime
View raw message