From 5fa5fbc496962394d84756b153bdb6e639fa6c97 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 15 Nov 2017 16:07:38 -0500 Subject: [PATCH] edge hates `for of` loops --- src/models/domain/cipher.ts | 8 +-- src/models/request/cipherRequest.ts | 4 +- src/models/response/cipherResponse.ts | 4 +- src/popup/app/current/current.component.ts | 55 +++++++++----------- src/popup/app/services/validation.service.ts | 4 +- 5 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/models/domain/cipher.ts b/src/models/domain/cipher.ts index 208688398e..80fd5d62d8 100644 --- a/src/models/domain/cipher.ts +++ b/src/models/domain/cipher.ts @@ -71,18 +71,18 @@ class Cipher extends Domain { if (obj.attachments != null) { this.attachments = []; - for (const attachment of obj.attachments) { + obj.attachments.forEach((attachment) => { this.attachments.push(new Attachment(attachment, alreadyEncrypted)); - } + }); } else { this.attachments = null; } if (obj.fields != null) { this.fields = []; - for (const field of obj.fields) { + obj.fields.forEach((field) => { this.fields.push(new Field(field, alreadyEncrypted)); - } + }); } else { this.fields = null; } diff --git a/src/models/request/cipherRequest.ts b/src/models/request/cipherRequest.ts index e037f53aae..659ee5be2d 100644 --- a/src/models/request/cipherRequest.ts +++ b/src/models/request/cipherRequest.ts @@ -74,13 +74,13 @@ class CipherRequest { if (cipher.fields) { this.fields = []; - for (const field of cipher.fields) { + cipher.fields.forEach((field: any) => { this.fields.push({ type: field.type, name: field.name ? field.name.encryptedString : null, value: field.value ? field.value.encryptedString : null, }); - } + }); } } } diff --git a/src/models/response/cipherResponse.ts b/src/models/response/cipherResponse.ts index a99f744e65..be7b65da97 100644 --- a/src/models/response/cipherResponse.ts +++ b/src/models/response/cipherResponse.ts @@ -25,9 +25,9 @@ class CipherResponse { if (response.Attachments != null) { this.attachments = []; - for (const attachment of response.Attachments) { + response.Attachments.forEach((attachment: any) => { this.attachments.push(new AttachmentResponse(attachment)); - } + }); } } } diff --git a/src/popup/app/current/current.component.ts b/src/popup/app/current/current.component.ts index ec0756811f..4ba3829355 100644 --- a/src/popup/app/current/current.component.ts +++ b/src/popup/app/current/current.component.ts @@ -1,3 +1,5 @@ +import { CipherType } from '../../../enums/cipherType.enum'; + import { UtilsService } from '../../../services/abstractions/utils.service'; import * as template from './current.component.html'; @@ -15,10 +17,8 @@ class CurrentController { disableSearch: boolean = false; constructor($scope: any, private cipherService: any, private utilsService: UtilsService, private toastr: any, - private $window: any, private $state: any, private $timeout: any, private autofillService: any, - private $analytics: any, private i18nService: any, private constantsService: any, - private $filter: any) { - + private $window: any, private $state: any, private $timeout: any, private autofillService: any, + private $analytics: any, private i18nService: any, private $filter: any) { this.i18n = i18nService; this.inSidebar = utilsService.inSidebar($window); this.disableSearch = utilsService.isEdge(); @@ -67,25 +67,22 @@ class CurrentController { this.toastr.error(this.i18nService.autofillError); } - this.autofillService - .doAutoFill({ - cipher, - pageDetails: this.pageDetails, - fromBackground: false, - }) - .then((totpCode: string) => { - this.$analytics.eventTrack('Autofilled'); - if (totpCode && this.utilsService.isFirefox()) { - this.utilsService.copyToClipboard(totpCode, document); - } - if (this.utilsService.inPopup(this.$window)) { - this.$window.close(); - } - }) - .catch(() => { - this.$analytics.eventTrack('Autofilled Error'); - this.toastr.error(this.i18nService.autofillError); - }); + this.autofillService.doAutoFill({ + cipher, + pageDetails: this.pageDetails, + fromBackground: false, + }).then((totpCode: string) => { + this.$analytics.eventTrack('Autofilled'); + if (totpCode && this.utilsService.isFirefox()) { + this.utilsService.copyToClipboard(totpCode, document); + } + if (this.utilsService.inPopup(this.$window)) { + this.$window.close(); + } + }).catch(() => { + this.$analytics.eventTrack('Autofilled Error'); + this.toastr.error(this.i18nService.autofillError); + }); } searchVault() { @@ -116,21 +113,21 @@ class CurrentController { }); const otherTypes = [ - this.constantsService.cipherType.card, - this.constantsService.cipherType.identity, + CipherType.Card, + CipherType.Identity, ]; - this.cipherService.getAllDecryptedForDomain(this.domain, otherTypes).then((ciphers: any) => { + this.cipherService.getAllDecryptedForDomain(this.domain, otherTypes).then((ciphers: any[]) => { const loginCiphers: any = []; const otherCiphers: any = []; - for (const cipher of ciphers) { - if (cipher.type === this.constantsService.cipherType.login) { + ciphers.forEach((cipher) => { + if (cipher.type === CipherType.Login) { loginCiphers.push(cipher); } else { otherCiphers.push(cipher); } - } + }); this.$timeout(() => { this.loginCiphers = this.$filter('orderBy')( diff --git a/src/popup/app/services/validation.service.ts b/src/popup/app/services/validation.service.ts index a31829837e..21b61e8343 100644 --- a/src/popup/app/services/validation.service.ts +++ b/src/popup/app/services/validation.service.ts @@ -13,11 +13,11 @@ class ValidationService { } else if (!data.validationErrors) { errors.push(data.message ? data.message : defaultErrorMessage); } else { - for (const error of data.validationErrors) { + data.validationErrors.forEach((error: any) => { error.forEach((item: string) => { errors.push(item); }); - } + }); } if (errors.length) {