Results 1 to 3 of 3

Thread: Load and Set Global Variable value from DB before app launch

  1. #1
    Sencha User =NR='s Avatar
    Join Date
    Mar 2013
    Location
    Singapore
    Posts
    115
    Answers
    2

    Default Load and Set Global Variable value from DB before app launch

    Hi there,

    I need to load value from localstorage / db on each device and set it to global variable before the app launch event,

    I tried the app onReady function but with this period my other class "DBOperation" isn't ready yet (I setup the up and connection in this class initialization)

    any suggestion on how to do this?

    PS: I do realize there are 2 ways of doing "Globa Variable" one is to define a variable before the Extdefine of your class, the other is to use app.namespace to be honest I don't mind whicever method I need to use to complete this requirement).

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    There isn't functionality to delay the launch method execution. What you should do is in the launch method check to see if the request has been loaded. If not then add an event listener to the request load. When the request loads, you can fire an event saying the request has finished loading.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    Sencha User
    Join Date
    May 2011
    Posts
    61
    Answers
    5

    Default

    I found a simple solution:
    1. Save the value of your global variable into local storage as a simple key/value pair, with this statement, inside your app:
      Code:
      localStorage.setItem('stg', JSON.stringify(stg));
    2. In "index.html" (in the head section), add the following code:
      Code:
      <script type="text/javascript">
      var defaultStg = {...},
          stg = JSON.parse(localStorage.getItem('stg')) || defaultStg;
      </script>
      "defaultStg" must be defined, because when app first start after install, local storage is empty!
    I'm not sure that this is an "academic" solution.
    However, it works perfectly:
    • the global var is setup before anything is loaded inside the app
    • the global var is available anywhere in the app

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •