You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2014/11/11 23:08:29 UTC

[13/28] git commit: [flex-asjs] [refs/heads/develop] - sync up StatesImpl with the AS version

sync up StatesImpl with the AS version


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

Branch: refs/heads/develop
Commit: 8649231302a2c1a985eadf0af30bbad96837d3b7
Parents: afd6ad9
Author: Alex Harui <ah...@apache.org>
Authored: Thu Nov 6 23:11:57 2014 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Nov 11 14:07:58 2014 -0800

----------------------------------------------------------------------
 frameworks/js/FlexJS/src/mx/states/AddItems.js  | 17 ++++
 .../js/FlexJS/src/mx/states/SetEventHandler.js  | 91 ++++++++++++++++++++
 .../org/apache/flex/core/SimpleStatesImpl.js    | 28 ++++--
 3 files changed, 131 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86492313/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 215bdb5..31cd682 100644
--- a/frameworks/js/FlexJS/src/mx/states/AddItems.js
+++ b/frameworks/js/FlexJS/src/mx/states/AddItems.js
@@ -44,6 +44,15 @@ mx.states.AddItems.prototype.FLEXJS_CLASS_INFO =
 mx.states.AddItems.prototype.setDocument = function(document, opt_id) {
   opt_id = typeof opt_id !== 'undefined' ? opt_id : null;
   this.document = document;
+  var data = document.mxmlsd[itemsDescriptorIndex];
+  if (typeof(data.slice) == 'function') {
+  	itemsDescriptor = {};
+    itemsDescriptor.descriptor = data;
+    // replace the entry in the document so subsequent
+    // addItems know it is shared
+    document.mxmlsd[itemsDescriptorIndex] = itemsDescriptor;
+  } else
+    itemsDescriptor = data;
 };
 
 
@@ -63,6 +72,14 @@ mx.states.AddItems.prototype.items = null;
 
 /**
  * @expose
+ * @type {Array} itemsDescriptor The index into the array 
+ *                               of itemDescriptors on the document
+ */
+mx.states.AddItems.prototype.itemsDescriptorIndex;
+
+
+/**
+ * @expose
  * @type {Array} itemsDescriptor The descriptors for items.
  */
 mx.states.AddItems.prototype.itemsDescriptor = null;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86492313/frameworks/js/FlexJS/src/mx/states/SetEventHandler.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/mx/states/SetEventHandler.js b/frameworks/js/FlexJS/src/mx/states/SetEventHandler.js
new file mode 100644
index 0000000..35e583d
--- /dev/null
+++ b/frameworks/js/FlexJS/src/mx/states/SetEventHandler.js
@@ -0,0 +1,91 @@
+/**
+ * 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('mx.states.SetEventHandler');
+
+goog.require('org.apache.flex.core.IDocument');
+
+
+
+/**
+ * @constructor
+ * @implements {org.apache.flex.core.IDocument}
+ */
+mx.states.SetEventHandler = function() {
+};
+
+
+/**
+ * Metadata
+ *
+ * @type {Object.<string, Array.<Object>>}
+ */
+mx.states.SetEventHandler.prototype.FLEXJS_CLASS_INFO =
+    { names: [{ name: 'SetEventHandler',
+                qName: 'mx.states.SetEventHandler' }],
+      interfaces: [org.apache.flex.core.IDocument] };
+
+
+/**
+ * @param {Object} document The MXML object.
+ * @param {?string=} opt_id The id.
+ */
+mx.states.SetEventHandler.prototype.setDocument = function(document, opt_id) {
+  opt_id = typeof opt_id !== 'undefined' ? opt_id : null;
+  this.document = document;
+};
+
+
+/**
+ * @expose
+ * @type {Object} document The MXML object.
+ */
+mx.states.SetEventHandler.prototype.document = null;
+
+
+/**
+ * @expose
+ * @type {string} name The event to listen for.
+ */
+mx.states.SetEventHandler.prototype.name = '';
+
+
+/**
+ * @expose
+ * @type {string} target The id of the object.
+ */
+mx.states.SetEventHandler.prototype.target = '';
+
+
+/**
+ * @expose
+ * @type {Object} handlerFunction The listener to be added.
+ */
+mx.states.SetEventHandler.prototype.handlerFunction = null;
+
+
+/**
+ * @expose
+ * @param {Object} properties The properties for the new object.
+ * @return {Object} The new object.
+ */
+mx.states.SetEventHandler.prototype.initializeFromObject = function(properties) {
+  var p;
+
+  for (p in properties) {
+    this[p] = properties[p];
+  }
+
+  return this;
+};

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/86492313/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 9813730..6a1d99c 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/core/SimpleStatesImpl.js
@@ -16,6 +16,7 @@ goog.provide('org.apache.flex.core.SimpleStatesImpl');
 
 goog.require('mx.states.AddItems');
 goog.require('mx.states.SetProperty');
+goog.require('mx.states.SetEventHandler');
 goog.require('mx.states.State');
 goog.require('org.apache.flex.core.IBead');
 goog.require('org.apache.flex.core.IStatesImpl');
@@ -155,6 +156,13 @@ org.apache.flex.core.SimpleStatesImpl.prototype.revert_ = function(s) {
       } else {
         target[o.name] = o.previousValue;
       }
+    } else if (org.apache.flex.utils.Language.is(o, mx.states.SetEventHandler)) {
+      if (typeof(o.document['get_' + o.target]) === 'function') {
+        target = o.document['get_' + o.target]();
+      } else {
+        target = o.document[o.target];
+      }
+      target.removeEventListener(o.name, o.handlerFunction);
     }
   }
 };
@@ -175,11 +183,14 @@ org.apache.flex.core.SimpleStatesImpl.prototype.apply_ = function(s) {
     o = arr[p];
     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;
+      	o.items = o.itemsDescriptor.items;
+        if (o.items == null)
+        {
+        	ai.items = 
+            	MXMLDataInterpreter.generateMXMLArray(o.document,
+                                    null, ai.itemsDescriptor.descriptor);
+            o.itemsDescriptor.items = ai.items;
+         }
       }
 
       for (q in o.items) {
@@ -234,6 +245,13 @@ org.apache.flex.core.SimpleStatesImpl.prototype.apply_ = function(s) {
       } else {
         target[o.name] = o.value;
       }
+    } else if (org.apache.flex.utils.Language.is(o, mx.states.SetEventHandler)) {
+      if (typeof(o.document['get_' + o.target]) === 'function') {
+        target = o.document['get_' + o.target]();
+      } else {
+        target = o.document[o.target];
+      }
+      target.addEventListener(o.name, o.handlerFunction);
     }
   }
 };