Closed jshepler closed 9 months ago
Hello, I have exposed the state of the App instance to window.appState
in v0.9.1. You can now use the handlers defined in src/containers/App.js, e.g.,
appState.handleEquipItem(75);
let hackstats = appState.hackstats;
hackstats.rpow = 1e9;
appState.handleSettings('hackstats', hackstats);
Using the handlers should re-render as expected.
Hope this helps!
Excellent, thank you.
Something isn't quite right or I'm doing something wrong. In the console, if I look at appState.savedequip
it's an array with a single item that's the empty slot instead of the 14 slots (13 plus the empty slot) I have.
Oops, looks like that only kept the initial (=empty) state, and only the handlers were properly exposed.
I made a change in v0.9.2, so the handlers reside in window.appHandlers
, and the actual state in window.appState
, now the previous example becomes
let hackstats = appState.hackstats; // access from appState
hackstats.rpow = 1e9;
appHandlers.handleSettings('hackstats', hackstats); // modify with appHandlers
If you modify the state (window.appState
) directly, then changes will not stick and no rerendering will be done, to save the changes you can do appHandlers.handleSaveStateLocalStorage(appState)
, and to rerender you have to reload. If you use the handlers to make changes, then everything should work as expected.
And appState.savedequip
should now show what you expect.
Perfect, working as expected. Thanks for quick fix.
I've written a couple mods that works with GO to do a few things. On the GO side, I use bookmarklets to run some js to do whatever, but it seems webpack isn't exposing a method to access the modules so I'm reading/updating local storage.
I have basically put a web service inside the game and the bookmarklets sends requests to it. Currently, I'm sending loadouts to NGU, getting hack stats from NGU, and sending hack goals (targets) to NGU. When updating the data in local storage, I reload the page so that app is using the updated data.
This works, but it's a bit clunky.
Would you consider exposing something on the window object that I could use instead of reading/updating local storage? Optimally, it should let me update values in a way that would cause react to re-render appropriately.