You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ha...@apache.org on 2016/04/08 13:19:10 UTC
[07/43] git commit: [flex-asjs] [refs/heads/e4x] - Changed Storage
package LocalStorage class to use same function names as web storage API for
better cross-compatibility. Also changed storage data type to String from
Object to maintain that compatibilit
Changed Storage package LocalStorage class to use same function names as web storage API for better cross-compatibility. Also changed storage data type to String from Object to maintain that compatibility and provide a concrete data type.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/392faf58
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/392faf58
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/392faf58
Branch: refs/heads/e4x
Commit: 392faf58189d864a5b2f7acb5e020e906211925b
Parents: 5479450
Author: Peter Ent <pe...@apache.org>
Authored: Thu Feb 25 14:32:55 2016 -0500
Committer: Peter Ent <pe...@apache.org>
Committed: Thu Feb 25 14:32:55 2016 -0500
----------------------------------------------------------------------
.../org/apache/flex/storage/LocalStorage.as | 106 +++++++++++--------
1 file changed, 64 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/392faf58/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/LocalStorage.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/LocalStorage.as b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/LocalStorage.as
index a3a2b87..9edd82c 100644
--- a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/LocalStorage.as
+++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/LocalStorage.as
@@ -26,7 +26,7 @@ COMPILE::AS3 {
* The LocalStorage class allows apps to store small amounts of data
* locally, in the browser's permitted storage area. This data will persist
* between browser invocations. The data is stored in key=value pairs.
- *
+ *
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
@@ -35,17 +35,17 @@ COMPILE::AS3 {
*/
public class LocalStorage
{
-
+
/**
* Constructor.
- *
+ *
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.0
* @flexjsignoreimport window
*/
- public function LocalStorage()
+ public function LocalStorage()
{
COMPILE::AS3 {
try {
@@ -55,13 +55,13 @@ public class LocalStorage
}
}
}
-
+
COMPILE::AS3
private var sharedObject:SharedObject;
-
+
/**
* Returns true if the platform provides local storage.
- *
+ *
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
@@ -71,11 +71,11 @@ public class LocalStorage
public function storageAvailable():Boolean
{
var result:Boolean = false;
-
+
COMPILE::AS3 {
result = (sharedObject != null);
}
-
+
COMPILE::JS {
try {
result = 'localStorage' in window && window['localStorage'] !== null;
@@ -83,115 +83,137 @@ public class LocalStorage
result = false;
}
}
-
+
return result;
}
-
+
/**
* Stores a value with a key. The value may be converted to a String, depending
* on the platform.
- *
+ *
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.0
* @flexjsignoreimport window
*/
- public function setValue(key:String, value:Object) : Boolean
+ public function setItem(key:String, value:String) : Boolean
{
if (!storageAvailable()) return false;
-
+
COMPILE::AS3 {
sharedObject.data[key] = value;
sharedObject.flush();
}
-
+
COMPILE::JS {
- window.localStorage[key] = value;
+ window.localStorage.setItem(key, value);
}
-
+
return true;
}
-
+
/**
* Returns the value associated with the key, or undefined if there is
* no value stored. Note that a String version of the value may have been
* stored, depending on the platform.
- *
+ *
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.0
* @flexjsignoreimport window
*/
- public function getValue(key:String) : Object
+ public function getItem(key:String) : String
{
if (!storageAvailable()) return null;
-
- var result:Object = null;
-
+
+ var result:String = null;
+
COMPILE::AS3 {
- result = sharedObject.data[key];
+ result = sharedObject.data[key] as String;
}
-
+
COMPILE::JS {
- result = window.localStorage[key];
+ result = window.localStorage.getItem(key);
}
-
+
return result;
}
-
+
/**
* Removed the value and, possibly, the key from local storage. On some
* platforms, retriving the value after removing it will be an error, on
* others it may return undefined or null.
- *
+ *
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.0
* @flexjsignoreimport window
*/
- public function removeValue(key:String) : Boolean
+ public function removeItem(key:String) : Boolean
{
if (!storageAvailable()) return null;
-
+
COMPILE::AS3 {
delete sharedObject.data[key];
sharedObject.flush();
}
-
+
COMPILE::JS {
- window.localStorage[key] = null;
+ window.localStorage.removeItem(key);
}
-
+
return true;
}
-
+
/**
* Returns true if there is a value stored for the key.
- *
+ *
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.0
* @flexjsignoreimport window
*/
- public function hasValue(key:String) : Boolean
+ public function hasItem(key:String) : Boolean
{
if (!storageAvailable()) return false;
-
+
var result:Boolean = false;
-
+
COMPILE::AS3 {
result = sharedObject.data.hasOwnProperty(key);
}
-
+
COMPILE::JS {
result = (window.localStorage[key] !== null);
}
-
+
return result;
}
+
+ /**
+ * Clears all values from local storage.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ * @flexjsignoreimport window
+ */
+ public function clear() : void
+ {
+ if (!storageAvailable()) return;
+
+ COMPILE::AS3 {
+ sharedObject.clear();
+ }
+
+ COMPILE::JS {
+ window.localStorage.clear();
+ }
+ }
+}
}
-}
\ No newline at end of file