-
Notifications
You must be signed in to change notification settings - Fork 80
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
JSON Changes Do Not Persist #149
Comments
Hi @Unknown025 , That sounds pretty strange. We have many tests that cover similar scenarios (https://github.com/electron-userland/electron-json-storage/blob/master/tests/storage.spec.js) and most What operating system are you running this on? How does the object look like? I'm wondering if this is related to the fact that you are running this code inside a React component. React component functions as synchronous, so they won't wait for the In any case, I'm not a front-end developer, but I believe that having async code inside a React render function is an anti-pattern.
Sounds like multiple executions of that component render function might be re-using the same object pointer, therefore they modify each other in weird ways. This module does Can you confirm if this works outside of a react component? i.e. running once at initialisation of the web app? |
I'm running on Windows 10, though intend to also test on macOS. The object I'd like to save looks something like this: I tried running outside of React, during the initialization of the application, and have confirmed that Thanks for the help, I appreciate it. One last question though, is there any way to save a file with "pretty printing", instead of saving the object as a single line string? |
I'm glad you figured it out!
We don't support that, but it would be interesting to support an option to pretty print before saving. This is the line that stringifies the object if you are up for sending a PR: https://github.com/electron-userland/electron-json-storage/blob/master/lib/storage.js#L316 |
#151 Alright, I've sent a PR. |
Hello there!
I've been trying to figure out a very simple problem, and have come to a solution that doesn't sit well with me, so I wanted to reach out and double check.
I have some functionality that requires reading from a key, making changes to the object retrieved from that key, and writing those changes back to the original key. The problem is that the changes I make to that key don't get saved. I've verified that the changes don't just vanish into thin air, via use of Electron/Chrome's debugger, and through console statements. The original value of the retrieved key gets written back to the file. Here's a relevant example: Gist
The only meaningful solution I've found so far is to stringify the result of
storage.get()
and parse it back to JSON, which doesn't seem like a good solution. Writing entirely different objects, without callingstorage.get()
, works as expected. Anything I'm doing wrong? I'm using Electron 10 (though I updated from Electron 6, which had the same problem) combined with React.I'm not an expert on JavaScript or Electron, so I'm hoping that I made a mistake somewhere. Everything is performed on the renderer, but I briefly tried using the backend process, to no avail.
Thanks in advance!
The text was updated successfully, but these errors were encountered: