Hybrid View

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    49
    Answers
    2
    Vote Rating
    3
    svendahlstrand is on a distinguished road

      1  

    Default Answered: Best practices to save user settings locally

    Answered: Best practices to save user settings locally


    Hello!

    Are there best practices when storing user settings locally in Sencha Touch? Example:

    A simple, one user, app where the user can change some settings - like background color, text size etcetera.

    Use case:
    • The user navigates to the settings view
    • The user changes some settings in an ordinary form
    • The user clicks save and the settings are persisted
    So I would like to use local storage for this. Can I use the model layer with a LocalStorage proxy? The way I see it, there's only one Settings object: a singleton. How do I handle that?

    Thanks!

  2. you can check the count of the store and work with a record with the same ID, should be only one record in the store. so if no record exist create one otherwise work with the existing one

  3. #2
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    690
    Answers
    21
    Vote Rating
    12
    mrsunshine will become famous soon enough

      1  

    Default


    yes, the easiest way is to create a settings model and store it in the localstorage

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    49
    Answers
    2
    Vote Rating
    3
    svendahlstrand is on a distinguished road

      0  

    Default


    How do I make sure that theres only one settings object persisted?

  5. #4
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    690
    Answers
    21
    Vote Rating
    12
    mrsunshine will become famous soon enough

      1  

    Default


    you can check the count of the store and work with a record with the same ID, should be only one record in the store. so if no record exist create one otherwise work with the existing one

  6. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Answers
    1
    Vote Rating
    0
    Ageris is on a distinguished road

      0  

    Default


    Before you put too much effort into using localstorage you should read this:

    http://www.softwareindustryinsights.com/2012/04/building-hybrid-apps-important-change-in-ios-5-1/

    Basically what it means is that the localstorage for WebViews (like phonegap and sencha) is now treated as a temporary store that can be cleared at any time by the OS. So do not trust it to remain after you application is closed.

  7. #6
    Sencha User
    Join Date
    Apr 2012
    Posts
    49
    Answers
    2
    Vote Rating
    3
    svendahlstrand is on a distinguished road

      0  

    Default


    Quote Originally Posted by Ageris View Post
    Basically what it means is that the localstorage for WebViews (like phonegap and sencha) is now treated as a temporary store that can be cleared at any time by the OS. So do not trust it to remain after you application is closed.
    Yeah I read about that in the Sencha blog. But if I understand it correctly theres no problem if my users add the app through Safari to the home screen?

  8. #7
    Sencha User
    Join Date
    Apr 2012
    Posts
    49
    Answers
    2
    Vote Rating
    3
    svendahlstrand is on a distinguished road

      0  

    Default


    Ok, the manual way then. I thought that maybe there is a function to save user settings through the framework. But now I now it doesn't. Thank you!

  9. #8
    Sencha User
    Join Date
    Feb 2012
    Location
    Illinois
    Posts
    93
    Vote Rating
    2
    bwags is on a distinguished road

      0  

    Default


    Quote Originally Posted by mrsunshine View Post
    you can check the count of the store and work with a record with the same ID, should be only one record in the store. so if no record exist create one otherwise work with the existing one
    I'm doing this, but notice that if I check the Resources tab in Chrome's Developer Tools under LocalStorage -> localhost, I can see that there are entries for both 'myUniqueProxy' and 'myUniqueProxy-0' (I set the id to the model to be 0).

    There are never any more entries in 'myUniqueProxy-0' other than the one I want, however it looks like there are tons entries for '0' in 'myUniquProxy'. Apparently one for every save despite it being the same record.

    Here's an image of what I'm seeing (don't pay attention to any malformed data, I modified it for this post):

    screenshot.png

    My proxy is setup like this:
    Code:
            proxy : {
                type : 'localstorage',
                id : 'myUniqueProxy',
            }
    My Model has an id field like this:
    Code:
           {
                name : 'id',
                type : 'integer',
                defaultValue : 0,
                isUnique : true
            }
    Then just like you said, I call for the store to getRecordById(0), update that record with current data and save it.

    Am I doing something wrong to get so many entries in the 'myUniqueProxy' entry?

    Thanks in advance for any advice.

    bwags
    Last edited by bwags; 19 Jun 2012 at 7:48 AM. Reason: Added image

  10. #9
    Sencha User
    Join Date
    Jun 2012
    Posts
    12
    Vote Rating
    -2
    jamie.mcleish has a little shameless behaviour in the past

      0  

    Default


    Hi there,

    I was wondering if you happened to find a workaround for this? When you reload the page do you automatically get more entries in local storage. There should only be one entry in localstorage which we update, but it appears to create new objects upon refresh.

    Thanks. :-)

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar