- Service Worker
- Indexdb
This commit is contained in:
6
src/globalroutines/index.js
Normal file
6
src/globalroutines/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import indexdb from './indexdb'
|
||||
|
||||
export default async (context, cmd, table, data = null) => {
|
||||
console.log('globalroutines', cmd, table, data)
|
||||
return await indexdb(context, cmd, table, data)
|
||||
}
|
||||
63
src/globalroutines/indexdb.js
Normal file
63
src/globalroutines/indexdb.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import store from '../store'
|
||||
import _ from 'lodash'
|
||||
import { UserStore } from '@modules'
|
||||
import { i18n } from '../plugins/i18n'
|
||||
|
||||
import {idbKeyval as storage} from '../js/storage.js';
|
||||
|
||||
function saveConfigIndexDb(context) {
|
||||
|
||||
let data = []
|
||||
data['_id'] = 1
|
||||
data['lang'] = UserStore.state.lang
|
||||
data['token'] = UserStore.state.idToken
|
||||
data['userId'] = UserStore.state.userId
|
||||
|
||||
writeConfigIndexDb('config', data)
|
||||
}
|
||||
|
||||
function writeConfigIndexDb(context, data) {
|
||||
console.log('writeConfigIndexDb', data)
|
||||
|
||||
storage.setdata('config', data)
|
||||
.then(ris => {
|
||||
return true
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async function readfromIndexDbToStateTodos(context) {
|
||||
console.log('*** read from IndexDb to state.todos')
|
||||
|
||||
return await storage.getalldata('todos')
|
||||
.then(ristodos => {
|
||||
console.log('&&&&&&& readfromIndexDbToStateTodos OK: Num RECORD: ', ristodos.length)
|
||||
UserStore.state.todos = ristodos
|
||||
}).catch((error) => {
|
||||
console.log('err: ', error)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
export default async (context, cmd, table, datakey) => {
|
||||
if (cmd === 'loadapp') {
|
||||
// ****** LOAD APP AL CARICAMENTO ! *******
|
||||
return saveConfigIndexDb(context, datakey)
|
||||
|
||||
|
||||
if ('indexedDB' in window) {
|
||||
if (!UserStore.state.networkDataReceived) {
|
||||
return await readfromIndexDbToStateTodos(context)
|
||||
}
|
||||
}
|
||||
|
||||
} else if (cmd === 'write') {
|
||||
return await storage.setdata(table, datakey)
|
||||
} else if (cmd === 'readall') {
|
||||
return await storage.getalldata(table)
|
||||
} else if (cmd === 'read') {
|
||||
return await storage.getdata(table, datakey)
|
||||
} else if (cmd === 'delete') {
|
||||
return await storage.deletedata(table, datakey)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user