locked
Winjs application level threads/objects

    Question

  • Hi,

    i'm wondering what the best approach is if you want certain objects to load on application level and not per html page.

    i have a few data dependant objects which i would like to load into application memory instead of having to reload them every html page.

    So far i'm toying with the idea of putting the data in the app.sessionstate

    any ideas?

    thanks

    Monday, July 16, 2012 6:22 AM

Answers

  • Hi

    That's depends on your data type.

    You can refer to this :

    Quickstart: Local application data (Metro style apps using JavaScript and HTML)

    Moreover, there're several options. Assume you use the navigation project template to create a multi-page project, a simple approach is to use a global object. You can put it in default.js, so every page can use it. Please do not put it inside the (function () block, otherwise it will not be visible on child pages.
     
    var AUniqueNameIdentifyingYourProject = new Object();

    (function () {
    ...
     
     
    Now whenever you want to use it, you can write:
     
    AUniqueNameIdentifyingYourProject.someItem = "some value";
     
    Note it is not recommended to use someItem directly as a global object, instead, please put all shared objects inside a single global object. And please also make sure AUniqueNameIdentifyingYourProject does not conflict with any libraries. This helps to ensure the global namespace is not polluted.



    Tuesday, July 17, 2012 8:35 AM

All replies

  • Hi

    That's depends on your data type.

    You can refer to this :

    Quickstart: Local application data (Metro style apps using JavaScript and HTML)

    Moreover, there're several options. Assume you use the navigation project template to create a multi-page project, a simple approach is to use a global object. You can put it in default.js, so every page can use it. Please do not put it inside the (function () block, otherwise it will not be visible on child pages.
     
    var AUniqueNameIdentifyingYourProject = new Object();

    (function () {
    ...
     
     
    Now whenever you want to use it, you can write:
     
    AUniqueNameIdentifyingYourProject.someItem = "some value";
     
    Note it is not recommended to use someItem directly as a global object, instead, please put all shared objects inside a single global object. And please also make sure AUniqueNameIdentifyingYourProject does not conflict with any libraries. This helps to ensure the global namespace is not polluted.



    Tuesday, July 17, 2012 8:35 AM
  • Ah i didn't think of that, i was already messing with the application session state.

    and this global will also still live after suspension which makes it ideal for what i'm trying to do

    Thursday, July 19, 2012 11:56 AM