Skip to content

Commit

Permalink
Unified initialization of the syncTasksCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
pkarw committed Apr 23, 2019
1 parent 6483988 commit 76a7575
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
8 changes: 2 additions & 6 deletions core/client-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,7 @@ const invokeClientEntry = async () => {
// event.data.config - configuration, endpoints etc
const storeView = currentStoreView()
const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : ''

const syncTaskCollection = new UniversalStorage(localForage.createInstance({
name: dbNamePrefix + 'shop',
storeName: 'syncTasks'
}))
const syncTaskCollection = Vue.prototype.$db.syncTaskCollection

const usersCollection = new UniversalStorage(localForage.createInstance({
name: (config.storeViews.commonCache ? '' : dbNamePrefix) + 'shop',
Expand Down Expand Up @@ -254,7 +250,7 @@ const invokeClientEntry = async () => {
mutex[id] = true // mark this task as being processed
fetchQueue.push(() => {
return execute(task, currentToken, currentCartId).then(executedTask => {
syncTaskCollection.removeItem(executedTask.task_id.toString()) // remove successfully executed task from the queue
syncTaskCollection.removeItem(id) // remove successfully executed task from the queue
mutex[id] = false
}).catch(err => {
mutex[id] = false
Expand Down
8 changes: 1 addition & 7 deletions core/lib/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ function execute (task) { // not offline task
/** Clear sync tasks that were not transmitted yet */
function clearNotTransmited () {
const storeView = currentStoreView()
const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : ''

const syncTaskCollection = new UniversalStorage(localForage.createInstance({
name: dbNamePrefix + 'shop',
storeName: 'syncTasks',
driver: localForage[rootStore.state.config.localForage.defaultDrivers['syncTasks']]
}))
const syncTaskCollection = Vue.prototype.$db.syncTaskCollection
syncTaskCollection.iterate((task, id, iterationNumber) => {
if (!task.transmited) {
syncTaskCollection.removeItem(id)
Expand Down

0 comments on commit 76a7575

Please sign in to comment.