- fix: updated from Store to Component: using Watch with 'immediate' parameters! @Watch('todos_changed', { immediate: true, deep: true })
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { ITodo, ITodosState } from 'model'
|
||||
import { IGlobalState, ITodo, ITodosState } from 'model'
|
||||
import { storeBuilder } from './Store/Store'
|
||||
|
||||
import Api from '@api'
|
||||
import { rescodes } from './rescodes'
|
||||
import { UserStore } from '@store'
|
||||
import { Todos, UserStore } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
|
||||
|
||||
const state: ITodosState = {
|
||||
visuOnlyUncompleted: false,
|
||||
networkDataReceived: false,
|
||||
todos: []
|
||||
todos: [],
|
||||
todos_changed: 1,
|
||||
testpao: 'Test'
|
||||
}
|
||||
|
||||
const b = storeBuilder.module<ITodosState>('TodosModule', state)
|
||||
@@ -29,8 +32,26 @@ namespace Getters {
|
||||
|
||||
namespace Mutations {
|
||||
|
||||
function setTestpao(state: ITodosState, testpao: String) {
|
||||
state.testpao = testpao
|
||||
}
|
||||
|
||||
function setTodos_changed(state: ITodosState) {
|
||||
state.todos_changed++
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
setTestpao: b.commit(setTestpao),
|
||||
setTodos_changed: b.commit(setTodos_changed),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function consolelogpao(strlog, strlog2 = '', strlog3 = '') {
|
||||
globalroutines(null, 'log', strlog + strlog2 + strlog3, null)
|
||||
}
|
||||
|
||||
|
||||
namespace Actions {
|
||||
|
||||
function json2array(json) {
|
||||
@@ -67,14 +88,42 @@ namespace Actions {
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROREEEEEEEEE')
|
||||
console.log('dbLoadTodo ERRORE', error)
|
||||
console.log(error)
|
||||
}
|
||||
// If error network connection, take the data from IndexedDb
|
||||
|
||||
return rescodes.ERR_GENERICO
|
||||
})
|
||||
|
||||
if (!Todos.state.networkDataReceived) {
|
||||
console.log('NETWORK UNREACHABLE ! (Error in fetch)')
|
||||
consolelogpao('NETWORK UNREACHABLE ! (Error in fetch)')
|
||||
// Read all data from IndexedDB Store into Memory
|
||||
await globalroutines(null, 'updateinMemory', 'todos', null)
|
||||
.then(() => {
|
||||
|
||||
testfunc()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function aspettansec(numsec) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
setTimeout(function () {
|
||||
resolve('anything')
|
||||
}, numsec)
|
||||
})
|
||||
}
|
||||
|
||||
async function testfunc() {
|
||||
while (true) {
|
||||
consolelogpao('testfunc')
|
||||
// Todos.mutations.setTodos_changed()
|
||||
Todos.state.todos_changed++
|
||||
console.log('Todos.state.todos_changed:', Todos.state.todos_changed)
|
||||
await aspettansec(5000)
|
||||
}
|
||||
}
|
||||
|
||||
async function dbSaveTodo(context, itemtodo: ITodo) {
|
||||
@@ -90,12 +139,12 @@ namespace Actions {
|
||||
console.log('ITEM', newItem)
|
||||
if (method === 'POST') {
|
||||
state.todos.push(newItem)
|
||||
// } else if (method === 'PATCH') {
|
||||
// state.todos.map(item => {
|
||||
// if (item._id === newItem._id) {
|
||||
// return newItem
|
||||
// }
|
||||
// })
|
||||
// } else if (method === 'PATCH') {
|
||||
// state.todos.map(item => {
|
||||
// if (item._id === newItem._id) {
|
||||
// return newItem
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +158,7 @@ namespace Actions {
|
||||
const token = UserStore.state.idToken
|
||||
|
||||
let res = await Api.SendReq(call, UserStore.state.lang, token, method, itemtodo)
|
||||
.then( function(response) {
|
||||
.then(function (response) {
|
||||
if (response)
|
||||
return response.json()
|
||||
else
|
||||
@@ -129,7 +178,7 @@ namespace Actions {
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROREEEEEEEEE')
|
||||
console.log('ERRORE FETCH', 'dbInsertSaveTodo', method)
|
||||
console.log(error)
|
||||
}
|
||||
return rescodes.ERR_GENERICO
|
||||
@@ -154,7 +203,7 @@ namespace Actions {
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROREEEEEEEEE', error)
|
||||
console.log('ERRORE FETCH', 'dbDeleteTodo')
|
||||
}
|
||||
return rescodes.ERR_GENERICO
|
||||
})
|
||||
@@ -187,7 +236,7 @@ const TodosModule = {
|
||||
return stateGetter()
|
||||
},
|
||||
getters: Getters.getters,
|
||||
// mutations: Mutations.mutations,
|
||||
mutations: Mutations.mutations,
|
||||
actions: Actions.actions
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import router from '@router'
|
||||
import { serv_constants } from '../Modules/serv_constants'
|
||||
import { rescodes } from '../Modules/rescodes'
|
||||
import { GlobalStore, UserStore, Todos } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
|
||||
const bcrypt = require('bcryptjs')
|
||||
|
||||
@@ -348,7 +349,7 @@ namespace Actions {
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROREEEEEEEEE')
|
||||
console.log('signup ERROREEEEEEEEE')
|
||||
console.log(error)
|
||||
}
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
@@ -450,8 +451,7 @@ namespace Actions {
|
||||
})
|
||||
.catch((error) => {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROREEEEEEEEE')
|
||||
console.log(error)
|
||||
console.log('signin ERRORE', error)
|
||||
}
|
||||
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return rescodes.ERR_GENERICO
|
||||
@@ -497,8 +497,11 @@ namespace Actions {
|
||||
GlobalStore.mutations.setCategorySel(localStorage.getItem(rescodes.localStorage.categorySel))
|
||||
|
||||
Todos.actions.dbLoadTodo()
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function autologin (context) {
|
||||
try {
|
||||
console.log('*** Autologin ***')
|
||||
|
||||
Reference in New Issue
Block a user