Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving/reading from LocalStorage just doing nothing. #33

Open
kamilk91 opened this issue Mar 11, 2020 · 1 comment
Open

Saving/reading from LocalStorage just doing nothing. #33

kamilk91 opened this issue Mar 11, 2020 · 1 comment

Comments

@kamilk91
Copy link

Hello

{
            bool initStart = true;

            bool startExist = store.Exists("start");
            if (!startExist)
            {


                initStart = true;
                store.Store("start", true);

            }

            if (initStart)
            {
                store.Store<bool>("start", true);
                store.Store<SingleUserData>("data", new SingleUserData { answers = new List<SingleUserAnswer>(), id = 1 });
            }
            else
            {
                var lastQuestion = store.Get<SingleUserData>("data");
                int lastQuestionId = lastQuestion.answers.Select(x => x.answerId).LastOrDefault();
            }

        }

Even if i added manualy "key" and "value" your library can't see it. The same situation is when i try to save something (simply boolean) in storage.

@hanssens
Copy link
Owner

Hi @kamilk91, if I simplify your sample it just works. See the example below. Also, all tests seem to prove the same.

// Store it
var key = "data";
store.Store<SingleUserData>(key, new SingleUserData { answers = new List<SingleUserAnswer>(), id = 42 });

// Fetch it
var target = store.Get<SingleUserData>(key);

// Prove it
Console.WriteLine(target.id);  // Prints: 42

Can it be that you're expecting it to be stored every time you run the program? In that case, you have to call the .Persist() operation before the routine closes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants