Giter VIP home page Giter VIP logo

Comments (4)

morphatic avatar morphatic commented on May 20, 2024 1

It turns out this issue was a result of state being asynchronously restored after mutations that were committed on page load. #107 introduces an event that gets emitted when the async store update has completed. Now that I understand the timing issues better, it all works as intended. Thanks for a great plugin!!!

from vuex-persist.

morphatic avatar morphatic commented on May 20, 2024

I found another (not very satisfactory) workaround that seems to confirm that the problem has something to do with the asynchronous nature of localForage. I revised my actions to look like this:

const sleep = ms => new Promise(res => setTimeout(res, ms));

const actions = {
  async login({ commit, dispatch }) {
    await sleep(500); // <-- FORCE A 500ms DELAY
    return login().then(
      res => {
        commit(LOGIN_SUCCESS, res); // <-- THIS COMMIT GETS PERSISTED NOW!
        return dispatch("getProfile", res.user_id);
      },
      err => commit(LOGIN_FAILURE, err)
    );
  },
  getProfile({ commit }, user_id) {
    commit(PROFILE_REQUEST);
    return api.getProfile(user_id).then(
      res => commit(PROFILE_SUCCESS, res),
      err => commit(PROFILE_FAILURE, err)
    );
  }
};

This workaround will allow me to continue working in development mode, but it's something I'll have to remember to remove before doing a production build. Also, it makes me worry that I don't fully understand the async issue and could have a bug in my production code...

from vuex-persist.

rulrok avatar rulrok commented on May 20, 2024

@morphatic See my new comment on #15 to see if it applies to you.

from vuex-persist.

championswimmer avatar championswimmer commented on May 20, 2024

please reopen if still issue remains

from vuex-persist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.