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

Commit

Permalink
refactor(Directives): use arrow notation, remove some return statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjors committed Dec 14, 2015
1 parent 1de0f23 commit d4227c0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions assets/js/directives/activity-feed.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ function activityFeed($http, Wallet, Activity) {
scope.activities = activities;
});

scope.$watch('status.didLoadTransactions', function (didLoad) {
scope.$watch('status.didLoadTransactions', (didLoad) => {
if (didLoad) {
Activity.updateTxActivities();
scope.loading = false;
}
});

scope.$watch('status.didLoadSettings', function (didLoad) {
scope.$watch('status.didLoadSettings', (didLoad) => {
if (didLoad) Activity.updateLogActivities();
});
}
Expand Down
26 changes: 12 additions & 14 deletions assets/js/directives/bc-async-input.directive.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

angular
.module('walletApp')
.directive('bcAsyncInput', bcAsyncInput);
Expand Down Expand Up @@ -52,56 +51,55 @@ function bcAsyncInput($timeout, Wallet) {
newValue: scope.ngModel
};

scope.edit = function () {
scope.edit = () => {
// finds and focuses on the text input field
// a brief timeout is necessary before trying to focus
$timeout((function () {
$timeout((() => {
elem.find('input')[0].focus();
}), 50);
return scope.status.edit = 1;
scope.status.edit = 1;
};

scope.focus = function () {
scope.focus = () => {
scope.status.edit = 1;
};

scope.validate = function () {
return scope.validator ? scope.validator(scope.form.newValue) : true;
};
scope.validate = () =>
scope.validator ? scope.validator(scope.form.newValue) : true;

scope.save = function () {
scope.save = () => {
scope.status.saving = true;

let success = function () {
let success = () => {
scope.ngModel = scope.form.newValue;
if (!attrs.custom) scope.bcAsyncForm.$setPristine();

// Fixes issue: hit enter after changing PBKDF2 iterations
// when 2nd password is enabled
scope.$evalAsync(function () {
scope.$evalAsync(() => {
scope.status.saving = false;
if (!attrs.editing) scope.status.edit = false;
});
scope.$root.$safeApply(scope);
};

let error = function () {
let error = () => {
scope.status.saving = false;
scope.$root.$safeApply(scope);
};

scope.onSave(scope.form.newValue, success, error);
};

scope.cancel = function () {
scope.cancel = () => {
if (!attrs.editing) scope.status.edit = false;
scope.bcAsyncForm.input.$rollbackViewValue();
scope.form.newValue = scope.ngModel;
scope.bcAsyncForm.$setPristine();
scope.onCancel && scope.onCancel();
};

transclude(scope, function (clone, scope) {
transclude(scope, (clone, scope) => {
if (attrs.custom) elem.empty().append(clone);
});
}
Expand Down
5 changes: 2 additions & 3 deletions assets/js/directives/configure-mobile-number.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ function configureMobileNumber(Wallet) {

scope.fields.newMobile = Wallet.user.internationalMobileNumber;

scope.numberChanged = () => {
return scope.fields.newMobile !== Wallet.user.internationalMobileNumber;
};
scope.numberChanged = () =>
scope.fields.newMobile !== Wallet.user.internationalMobileNumber;

scope.cancel = () => {
scope.fields.newMobile = Wallet.user.internationalMobileNumber;
Expand Down
6 changes: 3 additions & 3 deletions assets/js/directives/did-you-know.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function didYouKnow(DidYouKnow) {
return directive;

function link(scope, elem, attrs) {
scope.getRandInRange = (min, max) => {
return Math.floor(Math.random() * (max - min + 1) + min);
};
scope.getRandInRange = (min, max) =>
Math.floor(Math.random() * (max - min + 1) + min);

let randDYKIndex = scope.getRandInRange(0, DidYouKnow.dyks.length - 1);
scope.dyk = DidYouKnow.dyks[randDYKIndex];
}
Expand Down
5 changes: 4 additions & 1 deletion assets/js/directives/fiat-or-btc.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ function fiatOrBtc(Wallet, currency) {
scope.currency = scope.settings.displayCurrency;
scope.isBitCurrency = currency.isBitCurrency;

scope.updateDisplay = () => scope.currency = Wallet.settings.displayCurrency;
scope.updateDisplay = () => {
scope.currency = Wallet.settings.displayCurrency;
}

scope.$watch('settings.displayCurrency', scope.updateDisplay);
}
}

0 comments on commit d4227c0

Please sign in to comment.