From 40dc22a317d6e109cdd517aaff17dbc581904f38 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Thu, 4 Jul 2019 22:58:15 +0300 Subject: [PATCH] Remove knockout-transformations dependency --- dev/Model/Email.js | 2 +- dev/Settings/Admin/Contacts.js | 18 ++++--- dev/Settings/Admin/Packages.js | 12 +++-- dev/Stores/Admin/Domain.js | 3 +- dev/Stores/User/Pgp.js | 4 +- dev/View/Popup/Compose.js | 6 +-- dev/View/Popup/Contacts.js | 96 +++++++++++++++------------------- package.json | 1 - tasks/config.js | 1 - yarn.lock | 4 -- 10 files changed, 69 insertions(+), 78 deletions(-) diff --git a/dev/Model/Email.js b/dev/Model/Email.js index 54946419d..274bebc41 100644 --- a/dev/Model/Email.js +++ b/dev/Model/Email.js @@ -185,7 +185,7 @@ class EmailModel { const parsedResult = addressparser(line); if (isNonEmptyArray(parsedResult)) { return _.compact( - parsedResult.map((item) => + _.map(parsedResult, (item) => item.address ? new EmailModel(item.address.replace(/^[<]+(.*)[>]+$/g, '$1'), item.name || '') : null ) ); diff --git a/dev/Settings/Admin/Contacts.js b/dev/Settings/Admin/Contacts.js index 9e9beef35..d6bdcb385 100644 --- a/dev/Settings/Admin/Contacts.js +++ b/dev/Settings/Admin/Contacts.js @@ -47,14 +47,16 @@ class ContactsAdminSettings { this.contactsSupported = 0 < supportedTypes.length; this.contactsTypes = ko.observableArray([]); - this.contactsTypesOptions = this.contactsTypes.map((value) => { - const disabled = -1 === inArray(value, supportedTypes); - return { - 'id': value, - 'name': getTypeName(value) + (disabled ? ' (' + i18n('HINTS/NOT_SUPPORTED') + ')' : ''), - 'disabled': disabled - }; - }); + this.contactsTypesOptions = ko.computed(() => + _.map(this.contactsTypes(), (value) => { + const disabled = -1 === inArray(value, supportedTypes); + return { + 'id': value, + 'name': getTypeName(value) + (disabled ? ' (' + i18n('HINTS/NOT_SUPPORTED') + ')' : ''), + 'disabled': disabled + }; + }) + ); this.contactsTypes(types); this.contactsType = ko.observable(''); diff --git a/dev/Settings/Admin/Packages.js b/dev/Settings/Admin/Packages.js index 7ce46c076..2f01da872 100644 --- a/dev/Settings/Admin/Packages.js +++ b/dev/Settings/Admin/Packages.js @@ -18,9 +18,15 @@ class PackagesAdminSettings { this.packagesReal = PackageStore.packagesReal; this.packagesMainUpdatable = PackageStore.packagesMainUpdatable; - this.packagesCurrent = this.packages.filter((item) => item && '' !== item.installed && !item.compare); - this.packagesAvailableForUpdate = this.packages.filter((item) => item && '' !== item.installed && !!item.compare); - this.packagesAvailableForInstallation = this.packages.filter((item) => item && '' === item.installed); + this.packagesCurrent = ko.computed(() => + _.filter(this.packages(), (item) => item && '' !== item.installed && !item.compare) + ); + this.packagesAvailableForUpdate = ko.computed(() => + _.filter(this.packages(), (item) => item && '' !== item.installed && !!item.compare) + ); + this.packagesAvailableForInstallation = ko.computed(() => + _.filter(this.packages(), (item) => item && '' === item.installed) + ); this.visibility = ko.computed(() => (PackageStore.packages.loading() ? 'visible' : 'hidden')); } diff --git a/dev/Stores/Admin/Domain.js b/dev/Stores/Admin/Domain.js index b5f4710cc..a3bd0f069 100644 --- a/dev/Stores/Admin/Domain.js +++ b/dev/Stores/Admin/Domain.js @@ -1,10 +1,11 @@ +import _ from '_'; import ko from 'ko'; class DomainAdminStore { constructor() { this.domains = ko.observableArray([]); this.domains.loading = ko.observable(false).extend({ 'throttle': 100 }); - this.domainsWithoutAliases = this.domains.filter((item) => item && !item.alias); + this.domainsWithoutAliases = ko.computed(() => _.filter(this.domains(), (item) => item && !item.alias)); } } diff --git a/dev/Stores/User/Pgp.js b/dev/Stores/User/Pgp.js index 9d48a75d7..5c2f0600a 100644 --- a/dev/Stores/User/Pgp.js +++ b/dev/Stores/User/Pgp.js @@ -18,8 +18,8 @@ class PgpUserStore { this.openpgpkeys = ko.observableArray([]); this.openpgpKeyring = null; - this.openpgpkeysPublic = this.openpgpkeys.filter((item) => !!(item && !item.isPrivate)); - this.openpgpkeysPrivate = this.openpgpkeys.filter((item) => !!(item && item.isPrivate)); + this.openpgpkeysPublic = ko.computed(() => _.filter(this.openpgpkeys(), (item) => !!(item && !item.isPrivate))); + this.openpgpkeysPrivate = ko.computed(() => _.filter(this.openpgpkeys(), (item) => !!(item && item.isPrivate))); } /** diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index a2f3fba5a..0b6e3196e 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -226,9 +226,9 @@ class ComposePopupView extends AbstractViewNext { this.saving = ko.observable(false); this.attachments = ko.observableArray([]); - this.attachmentsInProcess = this.attachments.filter((item) => item && !item.complete()); - this.attachmentsInReady = this.attachments.filter((item) => item && item.complete()); - this.attachmentsInError = this.attachments.filter((item) => item && '' !== item.error()); + this.attachmentsInProcess = ko.computed(() => _.filter(this.attachments(), (item) => item && !item.complete())); + this.attachmentsInReady = ko.computed(() => _.filter(this.attachments(), (item) => item && item.complete())); + this.attachmentsInError = ko.computed(() => _.filter(this.attachments(), (item) => item && '' !== item.error())); this.attachmentsCount = ko.computed(() => this.attachments().length); this.attachmentsInErrorCount = ko.computed(() => this.attachmentsInError().length); diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 6b2832092..986bcc37e 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -98,27 +98,25 @@ class ContactsPopupView extends AbstractViewNext { this.viewSaveTrigger = ko.observable(SaveSettingsStep.Idle); - this.viewPropertiesNames = this.viewProperties.filter( - (property) => -1 < inArray(property.type(), [ContactPropertyType.FirstName, ContactPropertyType.LastName]) + this.viewPropertiesNames = ko.computed(() => + _.filter( + this.viewProperties(), + (property) => -1 < inArray(property.type(), [ContactPropertyType.FirstName, ContactPropertyType.LastName]) + ) + ); + this.viewPropertiesOther = ko.computed(() => + _.filter(this.viewProperties(), (property) => -1 < inArray(property.type(), [ContactPropertyType.Nick])) ); - // this.viewPropertiesOther = this.viewProperties.filter( - // (property) => -1 < inArray(property.type(), [ContactPropertyType.Note]) - // ); + this.viewPropertiesEmails = ko.computed(() => + _.filter(this.viewProperties(), (property) => ContactPropertyType.Email === property.type()) + ); - this.viewPropertiesOther = ko.computed(() => { - const list = _.filter( - this.viewProperties(), - (property) => -1 < inArray(property.type(), [ContactPropertyType.Nick]) - ); - return _.sortBy(list, (property) => property.type()); - }); + this.viewPropertiesWeb = ko.computed(() => + _.filter(this.viewProperties(), (property) => ContactPropertyType.Web === property.type()) + ); - this.viewPropertiesEmails = this.viewProperties.filter((property) => ContactPropertyType.Email === property.type()); - - this.viewPropertiesWeb = this.viewProperties.filter((property) => ContactPropertyType.Web === property.type()); - - this.viewHasNonEmptyRequaredProperties = ko.computed(() => { + this.viewHasNonEmptyRequiredProperties = ko.computed(() => { const names = this.viewPropertiesNames(), emails = this.viewPropertiesEmails(), fFilter = (property) => '' !== trim(property.value()); @@ -126,47 +124,37 @@ class ContactsPopupView extends AbstractViewNext { return !!(_.find(names, fFilter) || _.find(emails, fFilter)); }); - this.viewPropertiesPhones = this.viewProperties.filter((property) => ContactPropertyType.Phone === property.type()); - - this.viewPropertiesEmailsNonEmpty = this.viewPropertiesNames.filter((property) => '' !== trim(property.value())); - - this.viewPropertiesEmailsEmptyAndOnFocused = this.viewPropertiesEmails.filter((property) => { - const foc = property.focused(); - return '' === trim(property.value()) && !foc; - }); - - this.viewPropertiesPhonesEmptyAndOnFocused = this.viewPropertiesPhones.filter((property) => { - const foc = property.focused(); - return '' === trim(property.value()) && !foc; - }); - - this.viewPropertiesWebEmptyAndOnFocused = this.viewPropertiesWeb.filter((property) => { - const foc = property.focused(); - return '' === trim(property.value()) && !foc; - }); - - this.viewPropertiesOtherEmptyAndOnFocused = ko.computed(() => - _.filter(this.viewPropertiesOther(), (property) => { - const foc = property.focused(); - return '' === trim(property.value()) && !foc; - }) + this.viewPropertiesPhones = ko.computed(() => + _.filter(this.viewProperties(), (property) => ContactPropertyType.Phone === property.type()) ); - this.viewPropertiesEmailsEmptyAndOnFocused.subscribe((list) => { - fFastClearEmptyListHelper(list); - }); + this.viewPropertiesEmailsNonEmpty = ko.computed(() => + _.filter(this.viewPropertiesNames(), (property) => '' !== trim(property.value())) + ); - this.viewPropertiesPhonesEmptyAndOnFocused.subscribe((list) => { - fFastClearEmptyListHelper(list); - }); + const propertyFocused = (property) => { + const focused = property.focused(); + return '' === trim(property.value()) && !focused; + }; - this.viewPropertiesWebEmptyAndOnFocused.subscribe((list) => { - fFastClearEmptyListHelper(list); - }); + this.viewPropertiesEmailsEmptyAndOnFocused = ko.computed(() => + _.filter(this.viewPropertiesEmails(), propertyFocused) + ); - this.viewPropertiesOtherEmptyAndOnFocused.subscribe((list) => { - fFastClearEmptyListHelper(list); - }); + this.viewPropertiesPhonesEmptyAndOnFocused = ko.computed(() => + _.filter(this.viewPropertiesPhones(), propertyFocused) + ); + + this.viewPropertiesWebEmptyAndOnFocused = ko.computed(() => _.filter(this.viewPropertiesWeb(), propertyFocused)); + + this.viewPropertiesOtherEmptyAndOnFocused = ko.computed(() => + _.filter(this.viewPropertiesOther(), propertyFocused) + ); + + this.viewPropertiesEmailsEmptyAndOnFocused.subscribe(fFastClearEmptyListHelper); + this.viewPropertiesPhonesEmptyAndOnFocused.subscribe(fFastClearEmptyListHelper); + this.viewPropertiesWebEmptyAndOnFocused.subscribe(fFastClearEmptyListHelper); + this.viewPropertiesOtherEmptyAndOnFocused.subscribe(fFastClearEmptyListHelper); this.viewSaving = ko.observable(false); @@ -304,7 +292,7 @@ class ContactsPopupView extends AbstractViewNext { } @command((self) => { - const bV = self.viewHasNonEmptyRequaredProperties(), + const bV = self.viewHasNonEmptyRequiredProperties(), bReadOnly = self.viewReadOnly(); return !self.viewSaving() && bV && !bReadOnly; }) diff --git a/package.json b/package.json index 308d8e2c4..001e00d69 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,6 @@ "json3": "3.3.3", "knockout": "3.4.2", "knockout-sortable": "1.1.1", - "knockout-transformations": "2.1.0", "lozad": "1.9.0", "matchmedia-polyfill": "0.3.2", "moment": "2.24.0", diff --git a/tasks/config.js b/tasks/config.js index b447adb2c..bea665628 100644 --- a/tasks/config.js +++ b/tasks/config.js @@ -98,7 +98,6 @@ config.paths.js = { 'node_modules/underscore/underscore-min.js', 'node_modules/moment/min/moment.min.js', 'node_modules/knockout/build/output/knockout-latest.js', - 'node_modules/knockout-transformations/dist/knockout-transformations.min.js', 'node_modules/knockout-sortable/build/knockout-sortable.min.js ', 'node_modules/matchmedia-polyfill/matchMedia.js', 'node_modules/matchmedia-polyfill/matchMedia.addListener.js', diff --git a/yarn.lock b/yarn.lock index d990911ec..8e2f36662 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3884,10 +3884,6 @@ knockout-sortable@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/knockout-sortable/-/knockout-sortable-1.1.1.tgz#5375f02c61c30dcef4622f6e57e1bafa970d6a0e" -knockout-transformations@2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/knockout-transformations/-/knockout-transformations-2.1.0.tgz#c9a9148dbe1649dc00518eccea704379aadb0097" - knockout@3.4.2: version "3.4.2" resolved "https://registry.yarnpkg.com/knockout/-/knockout-3.4.2.tgz#e87958de77ad1e936f7ce645bab8b5d7c456d937"