electron-json-storage
electron-json-storage copied to clipboard
storage.set does not work in reducer
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.
@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.