Created
September 10, 2019 17:29
-
-
Save BastinRobin/968f266adfff3ebb2fbd7f309749c279 to your computer and use it in GitHub Desktop.
Sprax.js Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function() { | |
| window.sparx = window.sparx || {}; | |
| window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; | |
| window.addEventListener('online', updateSparxNetwork); | |
| window.addEventListener('offline', updateSparxNetworkOffline); | |
| sparx.check = { | |
| is_online: true | |
| }; | |
| function updateSparxNetwork() { | |
| sparx.check.is_online = true; | |
| } | |
| function updateSparxNetworkOffline() { | |
| sparx.check.is_online = false; | |
| } | |
| sparx.queue = function(item) { | |
| // Browser based DB can be used as a queue | |
| var request = indexedDB.open('sync_queue', 2); | |
| if (sparx.check.is_online) { | |
| axios.post('/v1/users', payload) | |
| .then(response => { | |
| console.log(response.data); | |
| }, error => (err) { | |
| console.log(repsonse.error) | |
| }) | |
| } else { | |
| sparx.queue.preserve(payload); | |
| } | |
| } | |
| /** | |
| * Sparx Insert Operation | |
| * | |
| * @param {<type>} payload The payload | |
| */ | |
| sparx.insert = function(payload) { | |
| sparx.queue.push(payload) | |
| } | |
| /** | |
| * Sparx Update Operation | |
| * | |
| * @param {<type>} id The identifier | |
| * @param {<type>} payload The payload | |
| */ | |
| sparx.update = function(id, payload) { | |
| } | |
| /** | |
| * Sparx Delete Operation | |
| */ | |
| sparx.delete = function(id) { | |
| } | |
| /** | |
| * Sparx Fetch Resource | |
| * | |
| * @param {<type>} id The identifier | |
| */ | |
| sparx.fetch = function(id) { | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment