Updating Storage File

Okay I implemented this strategy but the data entered in the app is not persistent still. I think it may be because my variables ‘pinfos’ and ‘vehicles’ are not observable? Also I came across this forum discussion - https://www.fusetools.com/community/forums/howto_discussions/how_do_i_each_an_observable_array?page=1 - could that have something to do with my problem?

My thought process is that on start-up the variables recieve their values that I have given. Then a storage file is read and if there is data within it the variables are changed to what is stored. If no storage file is found, one is created and the variables (with default values) are stored in the file. When the variables are updated by the user, the functions updateVehicles and updatePinfos will write the new values of the variables to the storage file. Does this flow not work or is my code not accomplishing the steps in the correct order? Fuse is not giving me any error codes.

Here is the link to my current project on github



I checked your project, and sadly there’s no quick solution. That’s mostly because you’re apparently lacking an understanding how reactive programming works, specifically Promises and Observables.

For example, this line never gets executed, because you’re returning from the function on line 83. Things inside of a promise-function need to be inside that promise. Note that promise implementation in Fuse is not Fuse-specific; it’s a JavaScript thing.

Then in several places, such as around here you’re referring to vehicles.value which implies that vehicles must be a single-value Observable. Well, first of all, semantically it should be a list, so referring to it by .value is wrong by itself. But, hey, look what I found right here! - it actually is just a plain JavaScript array. So basically all of the code that touches your vehicles variable in Backend.js is wrong, because your vehicles variable is not an Observable, and the array that it is does not have a property value. Should you turn it into an Observable? Unlikely, but more on that later.

What about a solution then? Well, you clearly have to fix the code in Backend.js and most likely in Context.js too - your Context is what translates your static data (stored JSON and its JavaScript-array represenation) to Observables and back; and I imagine that will yield further changes to your viewmodels too. You obviously should spend some more time reading how Observables in Fuse work, otherwise there’s very little hope of you getting it right.

I would like to suggest that you first get a minimal app working that does just one thing, like writing some JSON to a file and reading it; and only then move on to something larger. You will need to invest some time to gather the knowledge and experience.

Thank you for the help! I see the problem now, and yes I definitely have ALOT to learn but this was perfect, I re-did the whole backend.js and context.js (actually just got rid of it) and just had each page look/write directly to the storage file. It’s alot of extra code, but it’s what I know works and I’m am trying to finish this up real quick. I got this whole section working now thank you!