Skip to content

Commit

Permalink
performance optimizations of getting actual transactions and storing …
Browse files Browse the repository at this point in the history
…in storage.
  • Loading branch information
zyuhel committed Dec 3, 2017
1 parent 4b2bdf2 commit 2f6ce3c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/components/Transactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
return {
}
},
mounted: function () {
this.getTransactions()
},
watch: {
'$route': function (value) {
this.getTransactionInfo(value.params.tx_id)
Expand Down Expand Up @@ -62,7 +65,6 @@
return this.$store.state.address
},
transactions: function () {
this.getTransactions()
function compare (a, b) {
if (a.timestamp < b.timestamp) {
return 1
Expand All @@ -75,8 +77,6 @@
if (this.$store.state.transactions) {
return Object.values(this.$store.state.transactions).sort(compare)
}
// this.getTransactionInfo(this.$route.params.tx_id)
// return false
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/adamantServerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ function install (Vue) {
if (response.body.success) {
for (var i in response.body.transactions) {
if (response.body.transactions[i].type === 0) {
console.log('im here')
this.$store.commit('transaction_info', response.body.transactions[i])
}
}
Expand Down
29 changes: 28 additions & 1 deletion src/lib/lsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export default function storeData () {
clone: false
}))
}
window.onbeforeunload = function () {
window.ep.$store.commit('force_update')
}
store.subscribe((mutation, state) => {
var storeNow = false
if (mutation.type === 'change_storage_method') {
if (mutation.payload) {
useStorage = lsStorage
Expand All @@ -69,17 +73,40 @@ export default function storeData () {
lsStorage.removeItem('adm-persist')
}
mainStorage.setItem('storeInLocalStorage', mutation.payload)
storeNow = true
} else if (mutation.type === 'change_lang') {
mainStorage.setItem('language', mutation.payload)
storeNow = true
} else if (mutation.type === 'change_notify_sound') {
mainStorage.setItem('notify_sound', mutation.payload)
storeNow = true
} else if (mutation.type === 'change_notify_bar') {
mainStorage.setItem('notify_bar', mutation.payload)
storeNow = true
} else if (mutation.type === 'change_notify_desktop') {
mainStorage.setItem('notify_desktop', mutation.payload)
storeNow = true
}
if (mutation.type === 'save_passphrase') {
storeNow = true
}
if (mutation.type === 'force_update') {
storeNow = true
}
if (mutation.type !== 'transaction_info') {
if (mutation.type === 'ajax_start' || mutation.type === 'ajax_end' || mutation.type === 'ajax_end_with_error' || mutation.type === 'start_tracking_new' || mutation.type === 'have_loaded_chats' || mutation.type === 'connect' || mutation.type === 'login') {
return
}
if (storeNow) {
useStorage.setItem('adm-persist', JSON.stringify(state))
} else {
if (window.storeTimer) {
window.clearTimeout(window.storeTimer)
}
var storeTimer = window.setTimeout(function () {
window.ep.$store.commit('force_update')
window.storeTimer = undefined
}, 10000)
window.storeTimer = storeTimer
}
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const store = new Vuex.Store({
}
},
mutations: {
force_update (state) {
},
change_notify_sound (state, payload) {
state.notifySound = payload
},
Expand Down

0 comments on commit 2f6ce3c

Please sign in to comment.