Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Eliminate redundant Api calls. Closes #174 #210

Merged
merged 14 commits into from
May 15, 2017

Conversation

reyraa
Copy link
Contributor

@reyraa reyraa commented May 11, 2017

  • Remove recursive timeouts in all the components
  • Create a Sync service to manage intervals
  • Deep compare the result of status check and broadcast accountChange only if values are actually changed
  • Use camelCase for event names

@karmacoma karmacoma removed their assignment May 12, 2017
@reyraa reyraa requested a review from slaweet May 15, 2017 08:12
Copy link
Contributor

@slaweet slaweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, just some minor changes required.

@@ -1,14 +1,11 @@
import './transactions.less';

const UPDATE_INTERVAL = 20000;

app.component('transactions', {
template: require('./transactions.pug')(),
controller: class transactions {
constructor($scope, $rootScope, $timeout, $q, Peers, Account, AccountApi) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$timeout is should be removed from dependencies here.

}

// Calling listeners with the list of changes
$rootScope.$broadcast('onAccountChange', changes);
if (Object.keys(changes).length) {
$rootScope.$broadcast('accountChange', changes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$rootScope.$broadcast should be outside of keys.forEach((key) => {, because on each balance change it gets triggered twice. Because two properties change: balance and UnconfirmedBalance. Of course, the logic has to be updated accordingly.

}
this.$rootScope.$on('onAccountChange', () => {
this.init.call(this);
this.$rootScope.$on('accountChange', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.$rootScope.$on should be replaced with this.$scope.$on to prevent the callback being called multiple times, as described here:
http://stackoverflow.com/questions/30968948/angularjs-broadcast-once-on-twice

@@ -18,30 +15,23 @@ app.component('transactions', {
this.transactions = [];
this.pendingTransactions = [];

this.$rootScope.$on('transaction-sent', (event, transaction) => {
// Update transactions list if one was created
this.$rootScope.$on('transactionCreation', (event, transaction) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.$rootScope.$on should be replaced with this.$scope.$on to prevent the callback being called multiple times, as described here:
http://stackoverflow.com/questions/30968948/angularjs-broadcast-once-on-twice


if (this.account.get() && this.account.get().publicKey) {
this.checkIfIsDelegate();
this.$rootScope.$on('syncTick', this.update.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.$rootScope.$on should be replaced with this.$scope.$on to prevent the callback being called multiple times, as described here:
http://stackoverflow.com/questions/30968948/angularjs-broadcast-once-on-twice

return false;
}

const props1 = (ref1 instanceof Array) ? ref1.map((val, idx) => idx) : Object.keys(ref1).sort();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is calling for unit test coverage ;-) Something like calling Account.set with various values that cause go through all the paths here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this function does is to make sure we're updating list only when a real change is happening. so it doesn't perform a crucial task. though to meet 90+% it makes sense to cover it.

.then(() => {
this.$rootScope.prelogged = false;
this.$rootScope.logged = true;
this.checkIfIsDelegate();
if (this.$timeout) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the purpose of this if statement, but it looks weird. Maybe add some comment.

@reyraa reyraa merged commit 8b226f5 into development May 15, 2017
@reyraa reyraa deleted the 174-status-update-request branch May 15, 2017 13:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants