-1

I am developing a web app that allows users to create automations for creating tables. They can manually add rows to tables and edit them and they can as well have the option to create an automation which will autotmatically add rows to their table, based on the paramters that they choose (every x minutes, etc).

I simply used setInterval function with jquery and everytime they create an automation, the setinterval function runs and adds a new row to their table, incl. the paramters, it works perfectly.

The issue is of course when the page is refreshed, the interval is destroyed and so it becomes not very useful.

What can i do to "save" the interval function to memory, so it persists until the user manually removes it?

Uriel Bitton
  • 252
  • 6
  • 18

1 Answers1

-1

There will be a solution by using the localStorage or the sessionStorage which documentations you can find here Window.localStoage or Windows.sessionStorage.

Keep in my that you have limits, more about the limits of localStorage will you find by searching it or find posts on stackoverflow like this: What is the max size of localStorage values?

Also, I think you will get a poor performance by using JSON.stringify(). But if you want to store less and tiny data you can try something like this example on jsfiddle

The basic idea of the fiddle are these lines:

// data is an array and could keep objects ...
var data = [];

// save data array into localStorage
localStorage.setItem('interval-data', JSON.stringify(data));

// remove the data from the localStorage
localStorage.removeItem('interval-data');

// read the localStorage and convert the data back to an array
var storageData = JSON.parse(localStorage.getItem('interval-data'));

Finally, you should now consider whether it is better to store your data in a database.

UfguFugullu
  • 2,107
  • 13
  • 18
  • This doesn't help at all. once you reload the page the setInterval function doesn't resume. I explicitly mentioned this issue – Uriel Bitton Jun 19 '20 at 19:19
  • @UrielBitton The Interval could be started automatically but I have disabled that function in a comment. Before downvoting please look better to the solution in jsfiddle and read the full answer, then you also notice that this answer is CLEAR and USEFUL. This is can't be a copy-paste-solution because you have not posted a single line of code. – UfguFugullu Jun 23 '20 at 08:57