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

storage.set does not work in reducer #111

Open
Xsaven opened this issue Jul 18, 2018 · 1 comment
Open

storage.set does not work in reducer #111

Xsaven opened this issue Jul 18, 2018 · 1 comment

Comments

@Xsaven
Copy link

Xsaven commented Jul 18, 2018

i have a react reducer:

const fs = window.require('fs');
const path = window.require('path');
const settings = window.require('electron-settings');
const storage = window.require('electron-json-storage');
let server = settings.get('server') || false;
storage.setDataPath(path.join(server, '.lia'));

export default (state = (storage.get('dummy_list') || []), action) => {
  if(action.type=='DUMMY_ADD') {
    state[action.data.name] = action.data;
    console.log(state);
    storage.set('dummy_list', state, (error)=>{ console.log(error); });
    return state;
  }else
    return state;
};

and when this part is executed:
storage.set('dummy_list', state, (error)=>{ console.log(error); });
... nothing happens, the file creates, empty, but does not store the data there.

@jviotti
Copy link
Member

jviotti commented Jul 27, 2018

@Xsaven Can you provide a runnable example that I can use to reproduce?

Based on what I can see, though, you shouldn't be running an async function (like storage.set) in a sync reducer, since you're not waiting for this module to write the data before returning. If your reducer is called often enough, you could be overriding yourself each time.

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