Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.
/ offline-tasks Public archive

Library to save the task when there is no connection to the Internet, and run when an Internet connection will be

Notifications You must be signed in to change notification settings

notary/offline-tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

offline-tasks

Library to save the task when there is no connection to the Internet, and run when an Internet connection will be

Using

1. Create

    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
    });

2. Registration functions tasks

    offTasks.saveManagerRegistry('somaTasksName', function (taskData, callback) {
        //something do there
        callback('error'); //or other status
    });

3. Add tasks

    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'}

4. Load all tasks from provider

    var tasks = offTasks.load();

5. Load tasks by keys from provider

    var keys = ['key1', 'key2'];
    var tasks = offTasks.load(keys);

6. Run tasks

    // all tasks
    offTasks.run();
    // tasks by keys
    offTasks.run(keys);

7. Remove task

    offTasks.remove('key');

About

Library to save the task when there is no connection to the Internet, and run when an Internet connection will be

Resources

Stars

Watchers

Forks

Packages

No packages published