incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Colin Eberhardt (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-155) localStorage does not work with square brace notation
Date Fri, 06 Jan 2012 09:03:39 GMT

    [ https://issues.apache.org/jira/browse/CB-155?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13181209#comment-13181209
] 

Colin Eberhardt commented on CB-155:
------------------------------------

Hi Jesse,

No, there are no warnings on the VS debug output window if you use localStorage via dot or
square brace notation. For a simple example, try replacing the PG started app index.html with
the following:


<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0,
maximum-scale=1.0, user-scalable=no;" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
    <title>PhoneGap WP7</title>
    <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title"
charset="utf-8"/>
    <script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>
    <script type="text/javascript">
      document.addEventListener("deviceready",onDeviceReady,false);
            
      function onDeviceReady() {
        if (localStorage["myStatus"]) {
          document.getElementById("currentStatus").innerHTML = localStorage["myStatus"]; 
      
        }
      }
      
      function updateStatus() {
        var status = document.getElementById("statusInput").value;
        document.getElementById("currentStatus").innerHTML = status;
        localStorage["myStatus"] = status;
      }
    </script>
  </head>
  <body>
    <p>
      <b>Your status:</b>
      <span id="currentStatus"></span>
    </p>
    <p>
      <input id="statusInput"></input>
      <button onclick="updateStatus()">Update Status</button>
    </p>
  </body>
</html>

There is no warning that this will not work.

As a workaround, if I invoke the following code on application exit or deactivation (pause),
it will ensure that anythign added to localStorage via a property is persisted:

      function persistLocalStorage() {
        for(var prop in localStorage) {
          if(localStorage.hasOwnProperty(prop) && (typeof localStorage[prop] === 'string'))
{
            // invoke the setter in order to persist this property
            localStorage.setItem(prop, localStorage.prop);
          }
        }
      }

Could this technique be used by the PG framework?

Regards, Colin E.
                
> localStorage does not work with square brace notation
> -----------------------------------------------------
>
>                 Key: CB-155
>                 URL: https://issues.apache.org/jira/browse/CB-155
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: WP7
>    Affects Versions: 1.3.0
>            Reporter: Colin Eberhardt
>            Assignee: Jesse MacFadyen
>
> Currently the WP7 localStorage shim works if you use localStorage setItem / getItem methods,
however, it fails if you use the square brace notation:
> localStorage["key"] = someValue;

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message