Library to save the task when there is no connection to the Internet, and run when an Internet connection will be
var provider = window.localStorage;
var offTasks = new OfflineTasks({
provider: provider,
connectionTest: function (callback) {
//some connection test Function
callback(null, 'error'); //or other status
},
timeout: 10000, //check the connection timeout
autorun: false //to run the task immediately after saving
});
offTasks.saveManagerRegistry('somaTasksName', function (taskData, callback) {
//something do there
callback('error'); //or other status
});
var task1 = {data: 'example 1'};
var task2 = {data: 'example 2'};
offTasks.save('taskName', task1);
offTasks.save('taskName', task2);
// in the storage will be saved [{data: 'example 1'}, {data: 'example 2'}]
or
var tasks = {
taskname1: {data: 'example 1'},
taskname2: {data: 'example 2'}
};
offTasks.save(tasks); // in the storage will be saved 2 different task
var task1 = {data: 'example 1'};
var task2 = {data: 'example 2'};
offTasks.save('taskName', task1);
offTasks.save('taskName', task2, true); // rewrite tasks is true
// in the storage will be saved [{data: 'example 2'}]
or
var tasks = {
taskname1: {data: 'example 1'},
taskname2: {data: 'example 2'}
};
var tasks2 = {
taskname1: {data: 'example 3'},
taskname2: {data: 'example 4'}
};
offTasks.save(tasks);
offTasks.save(tasks, true); //in storage will saved {data: 'example 3'} and {data: 'example 4'}
var tasks = offTasks.load();
var keys = ['key1', 'key2'];
var tasks = offTasks.load(keys);
// all tasks
offTasks.run();
// tasks by keys
offTasks.run(keys);
offTasks.remove('key');