Global variable or database always

Asked

Viewed 71 times

1

I made an application using jQuery Mobile library, it is an application to split account.

I created a main object called conta and it is incremented according to the user’s actions (code below). As the pages are all in an HTML file, I used only one JS file as well and worked with the global variables to store information, since I don’t need to load the file to change pages. At the end, at the time of saving, I use JSON and pass the whole object conta for the localStorage.

Question

Should I always store and search the data in the database or can I use global variables to store data in situations where the page will not load the page? What is best practice?

Code:

/*********************************************************
Todo o codigo eh em funcao deste objeto, que esta sempre mudando
**************************************************************/
var conta = {

    idConta: 0,
    nomeConta: "",
    data: "",
    contaCarregada: false,

    pessoas: {
        pessoa: [], //nome + id
        quantAdd: 0,

    },

    produtos: {
        produto: [], //aqui vai id, nome, quant... de cada produto adicionado
        quantAdd: 0,
        totalInserido: 0
    },

    jaCalculado: false,
    produtoAlterado: false

};
  • My opinion: You can use a setTimeOut to occasionally see if something has changed and save in the bank. Imagine that someone closed the application unintentionally: If you have only the memory you will lose the information, if you have persisted you will be able to go back to where you left off.

  • I use global. Using settimeout is interesting. More do not use save without it because whenever someone changes something depending on the appliance can give a lock. Kk

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.