From 37dc8ebe5cc24ad6b7501093a5217711e75fc046 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 12 Jul 2022 21:23:00 -0400 Subject: [PATCH 1/2] Refactor computeds --- .github/workflows/ci.yml | 6 +++--- addon/classes/Column.js | 5 +++-- addon/classes/Table.js | 17 +++++++++-------- addon/components/cells/base.js | 3 ++- addon/components/columns/base.js | 15 ++++++++------- addon/components/light-table.js | 3 ++- addon/components/lt-body.js | 7 ++++--- addon/components/lt-row.js | 6 +++--- addon/mixins/table-header.js | 9 +++++---- tests/dummy/app/components/base-table.js | 5 +++-- .../components/cookbook/client-side-table.js | 9 ++++----- .../app/components/rows/selectable-table.js | 3 ++- 12 files changed, 48 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 416e4d8b..8aff2773 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,9 +45,9 @@ jobs: - ember-lts-3.20 - ember-lts-3.24 - ember-lts-3.28 - # - ember-release - # - ember-beta - # - ember-canary + - ember-release + - ember-beta + - ember-canary - ember-default-with-jquery - ember-classic - embroider-safe diff --git a/addon/classes/Column.js b/addon/classes/Column.js index dabef121..1dab47c1 100644 --- a/addon/classes/Column.js +++ b/addon/classes/Column.js @@ -1,5 +1,6 @@ import { A as emberArray, makeArray } from '@ember/array'; import EmberObject, { computed } from '@ember/object'; +import { notEmpty, or } from '@ember/object/computed'; import { isEmpty } from '@ember/utils'; import { guidFor } from '@ember/object/internals'; @@ -284,14 +285,14 @@ export default class Column extends EmberObject.extend({ * @property isHidden * @type {Boolean} */ - isHidden: computed.or('hidden', 'responsiveHidden').readOnly(), + isHidden: or('hidden', 'responsiveHidden'), /** * @property isGroupColumn * @type {Boolean} * @private */ - isGroupColumn: computed.notEmpty('subColumns').readOnly(), + isGroupColumn: notEmpty('subColumns'), /** * @property isVisibleGroupColumn diff --git a/addon/classes/Table.js b/addon/classes/Table.js index 01c2e87c..e4767a9d 100644 --- a/addon/classes/Table.js +++ b/addon/classes/Table.js @@ -1,6 +1,7 @@ import { A as emberArray, isArray } from '@ember/array'; import { assert } from '@ember/debug'; import EmberObject, { computed } from '@ember/object'; +import { empty, filterBy } from '@ember/object/computed'; import Row from 'ember-light-table/classes/Row'; import Column from 'ember-light-table/classes/Column'; import SyncArrayProxy from 'ember-light-table/-private/sync-array-proxy'; @@ -46,25 +47,25 @@ export default class Table extends EmberObject.extend({ * @property isEmpty * @type {Boolean} */ - isEmpty: computed.empty('rows').readOnly(), + isEmpty: empty('rows').readOnly(), /** * @property expandedRows * @type {Ember.Array} */ - expandedRows: computed.filterBy('rows', 'expanded', true).readOnly(), + expandedRows: filterBy('rows', 'expanded', true).readOnly(), /** * @property selectedRows * @type {Ember.Array} */ - selectedRows: computed.filterBy('rows', 'selected', true).readOnly(), + selectedRows: filterBy('rows', 'selected', true).readOnly(), /** * @property visibleRows * @type {Ember.Array} */ - visibleRows: computed.filterBy('rows', 'hidden', false).readOnly(), + visibleRows: filterBy('rows', 'hidden', false).readOnly(), /** * @property sortableColumns @@ -78,19 +79,19 @@ export default class Table extends EmberObject.extend({ * @property sortedColumns * @type {Ember.Array} */ - sortedColumns: computed.filterBy('visibleColumns', 'sorted', true).readOnly(), + sortedColumns: filterBy('visibleColumns', 'sorted', true).readOnly(), /** * @property hideableColumns * @type {Ember.Array} */ - hideableColumns: computed.filterBy('allColumns', 'hideable', true).readOnly(), + hideableColumns: filterBy('allColumns', 'hideable', true).readOnly(), /** * @property hiddenColumns * @type {Ember.Array} */ - hiddenColumns: computed.filterBy('allColumns', 'hidden', true).readOnly(), + hiddenColumns: filterBy('allColumns', 'hidden', true).readOnly(), /** * @property responsiveHiddenColumns @@ -104,7 +105,7 @@ export default class Table extends EmberObject.extend({ * @property visibleColumns * @type {Ember.Array} */ - visibleColumns: computed.filterBy('allColumns', 'isHidden', false).readOnly(), + visibleColumns: filterBy('allColumns', 'isHidden', false).readOnly(), /** * @property visibleColumnGroups diff --git a/addon/components/cells/base.js b/addon/components/cells/base.js index 1109bc79..443208b8 100644 --- a/addon/components/cells/base.js +++ b/addon/components/cells/base.js @@ -1,5 +1,6 @@ import Component from '@ember/component'; import { computed } from '@ember/object'; +import { readOnly } from '@ember/object/computed'; import layout from 'ember-light-table/templates/components/cells/base'; import { htmlSafe } from '@ember/template'; @@ -22,7 +23,7 @@ const Cell = Component.extend({ enableScaffolding: false, - isSorted: computed.readOnly('column.sorted'), + isSorted: readOnly('column.sorted'), style: computed('enableScaffolding', 'column.width', function () { let column = this.column; diff --git a/addon/components/columns/base.js b/addon/components/columns/base.js index 2a30e54f..ec089be9 100644 --- a/addon/components/columns/base.js +++ b/addon/components/columns/base.js @@ -1,6 +1,7 @@ import { set } from '@ember/object'; import Component from '@ember/component'; import { computed } from '@ember/object'; +import { oneWay, readOnly } from '@ember/object/computed'; import { isEmpty } from '@ember/utils'; import layout from 'ember-light-table/templates/components/columns/base'; import DraggableColumnMixin from 'ember-light-table/mixins/draggable-column'; @@ -33,12 +34,12 @@ const Column = Component.extend(DraggableColumnMixin, { 'column.classNames', ], - isGroupColumn: computed.readOnly('column.isGroupColumn'), - isSortable: computed.readOnly('column.sortable'), - isSorted: computed.readOnly('column.sorted'), - isHideable: computed.readOnly('column.hideable'), - isResizable: computed.readOnly('column.resizable'), - isDraggable: computed.readOnly('column.draggable'), + isGroupColumn: readOnly('column.isGroupColumn'), + isSortable: readOnly('column.sortable'), + isSorted: readOnly('column.sorted'), + isHideable: readOnly('column.hideable'), + isResizable: readOnly('column.resizable'), + isDraggable: readOnly('column.draggable'), isResizing: false, style: computed('column.width', function () { @@ -53,7 +54,7 @@ const Column = Component.extend(DraggableColumnMixin, { * @property label * @type {String} */ - label: computed.oneWay('column.label'), + label: oneWay('column.label'), /** * @property table diff --git a/addon/components/light-table.js b/addon/components/light-table.js index 870c7cd8..670bb0df 100644 --- a/addon/components/light-table.js +++ b/addon/components/light-table.js @@ -1,6 +1,7 @@ import { A as emberArray } from '@ember/array'; import Component from '@ember/component'; import { computed, observer } from '@ember/object'; +import { readOnly } from '@ember/object/computed'; import { isEmpty, isNone } from '@ember/utils'; import { assert } from '@ember/debug'; import { inject as service } from '@ember/service'; @@ -217,7 +218,7 @@ const LightTable = Component.extend({ } ).readOnly(), - visibleColumns: computed.readOnly('table.visibleColumns'), + visibleColumns: readOnly('table.visibleColumns'), /** * Calculates the total width of the visible columns via their `width` diff --git a/addon/components/lt-body.js b/addon/components/lt-body.js index f248ccad..aaa4e980 100644 --- a/addon/components/lt-body.js +++ b/addon/components/lt-body.js @@ -1,6 +1,7 @@ import Component from '@ember/component'; import { deprecate } from '@ember/application/deprecations'; import { computed, observer } from '@ember/object'; +import { readOnly } from '@ember/object/computed'; import layout from 'ember-light-table/templates/components/lt-body'; import { run } from '@ember/runloop'; import Row from 'ember-light-table/classes/Row'; @@ -317,9 +318,9 @@ export default Component.extend({ */ infinityComponent: null, - rows: computed.readOnly('table.visibleRows'), - columns: computed.readOnly('table.visibleColumns'), - colspan: computed.readOnly('columns.length'), + rows: readOnly('table.visibleRows'), + columns: readOnly('table.visibleColumns'), + colspan: readOnly('columns.length'), /** * fills the screen with row items until lt-infinity component has exited the viewport diff --git a/addon/components/lt-row.js b/addon/components/lt-row.js index 8a0c995c..16a37096 100644 --- a/addon/components/lt-row.js +++ b/addon/components/lt-row.js @@ -1,5 +1,5 @@ import Component from '@ember/component'; -import { computed } from '@ember/object'; +import { readOnly } from '@ember/object/computed'; import layout from 'ember-light-table/templates/components/lt-row'; const Row = Component.extend({ @@ -23,8 +23,8 @@ const Row = Component.extend({ canSelect: false, colspan: 1, - isSelected: computed.readOnly('row.selected'), - isExpanded: computed.readOnly('row.expanded'), + isSelected: readOnly('row.selected'), + isExpanded: readOnly('row.expanded'), }); Row.reopenClass({ diff --git a/addon/mixins/table-header.js b/addon/mixins/table-header.js index e6d088e7..3df5b272 100644 --- a/addon/mixins/table-header.js +++ b/addon/mixins/table-header.js @@ -1,5 +1,6 @@ import Mixin from '@ember/object/mixin'; import { computed, trySet } from '@ember/object'; +import { oneWay, readOnly } from '@ember/object/computed'; import { isEmpty } from '@ember/utils'; import { warn } from '@ember/debug'; import { inject as service } from '@ember/service'; @@ -127,10 +128,10 @@ export default Mixin.create({ */ tableId: null, - renderInPlace: computed.oneWay('fixed'), - columnGroups: computed.readOnly('table.visibleColumnGroups'), - subColumns: computed.readOnly('table.visibleSubColumns'), - columns: computed.readOnly('table.visibleColumns'), + renderInPlace: oneWay('fixed'), + columnGroups: readOnly('table.visibleColumnGroups'), + subColumns: readOnly('table.visibleSubColumns'), + columns: readOnly('table.visibleColumns'), sortIcons: computed( 'iconSortable', diff --git a/tests/dummy/app/components/base-table.js b/tests/dummy/app/components/base-table.js index e801fd2f..5e4980e5 100644 --- a/tests/dummy/app/components/base-table.js +++ b/tests/dummy/app/components/base-table.js @@ -1,6 +1,7 @@ // BEGIN-SNIPPET base-table import Component from '@ember/component'; -import { computed, action } from '@ember/object'; +import { action } from '@ember/object'; +import { oneWay } from '@ember/object/computed'; import { isEmpty } from '@ember/utils'; import { inject as service } from '@ember/service'; import Table from 'ember-light-table'; @@ -14,7 +15,7 @@ export default Component.extend({ dir: 'asc', sort: 'firstName', - isLoading: computed.oneWay('fetchRecords.isRunning'), + isLoading: oneWay('fetchRecords.isRunning'), canLoadMore: true, enableSync: true, diff --git a/tests/dummy/app/components/cookbook/client-side-table.js b/tests/dummy/app/components/cookbook/client-side-table.js index a26ffe16..86f268cc 100644 --- a/tests/dummy/app/components/cookbook/client-side-table.js +++ b/tests/dummy/app/components/cookbook/client-side-table.js @@ -1,6 +1,7 @@ // BEGIN-SNIPPET client-side-table import BaseTable from '../base-table'; import { computed, action } from '@ember/object'; +import { oneWay, or, sort } from '@ember/object/computed'; import { task, timeout } from 'ember-concurrency'; export default BaseTable.extend({ @@ -9,18 +10,16 @@ export default BaseTable.extend({ // No need for `enableSync` here enableSync: false, - isLoading: computed - .or('fetchRecords.isRunning', 'setRows.isRunning') - .readOnly(), + isLoading: or('fetchRecords.isRunning', 'setRows.isRunning'), // Sort Logic - sortedModel: computed.sort('model', 'sortBy').readOnly(), + sortedModel: sort('model', 'sortBy'), sortBy: computed('dir', 'sort', function () { return [`${this.sort}:${this.dir}`]; }).readOnly(), // Filter Input Setup - selectedFilter: computed.oneWay('possibleFilters.firstObject'), + selectedFilter: oneWay('possibleFilters.firstObject'), // eslint-disable-next-line ember/require-computed-macros possibleFilters: computed('table.columns', function () { return this.table.columns.filterBy('sortable', true); diff --git a/tests/dummy/app/components/rows/selectable-table.js b/tests/dummy/app/components/rows/selectable-table.js index 910508d3..1dd8f79c 100644 --- a/tests/dummy/app/components/rows/selectable-table.js +++ b/tests/dummy/app/components/rows/selectable-table.js @@ -1,9 +1,10 @@ // BEGIN-SNIPPET selectable-table import BaseTable from '../base-table'; import { computed, action } from '@ember/object'; +import { notEmpty } from '@ember/object/computed'; export default BaseTable.extend({ - hasSelection: computed.notEmpty('table.selectedRows'), + hasSelection: notEmpty('table.selectedRows'), columns: computed(function () { return [ From 0e8219d14129fedb1f60f10195fc55e4dce69b49 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 12 Jul 2022 21:36:54 -0400 Subject: [PATCH 2/2] Update more computeds --- addon/classes/Table.js | 12 ++++++------ package.json | 1 - yarn.lock | 27 +-------------------------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/addon/classes/Table.js b/addon/classes/Table.js index e4767a9d..591af185 100644 --- a/addon/classes/Table.js +++ b/addon/classes/Table.js @@ -71,9 +71,7 @@ export default class Table extends EmberObject.extend({ * @property sortableColumns * @type {Ember.Array} */ - sortableColumns: computed - .filterBy('visibleColumns', 'sortable', true) - .readOnly(), + sortableColumns: filterBy('visibleColumns', 'sortable', true).readOnly(), /** * @property sortedColumns @@ -97,9 +95,11 @@ export default class Table extends EmberObject.extend({ * @property responsiveHiddenColumns * @type {Ember.Array} */ - responsiveHiddenColumns: computed - .filterBy('allColumns', 'responsiveHidden', true) - .readOnly(), + responsiveHiddenColumns: filterBy( + 'allColumns', + 'responsiveHidden', + true + ).readOnly(), /** * @property visibleColumns diff --git a/package.json b/package.json index 2cf78040..99c76313 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,6 @@ "ember-export-application-global": "^2.0.1", "ember-load-initializers": "^2.1.2", "ember-maybe-import-regenerator": "^1.0.0", - "ember-one-way-controls": "^3.0.1", "ember-power-select": "^4.0.0", "ember-prism": "^0.12.0", "ember-qunit": "^5.1.4", diff --git a/yarn.lock b/yarn.lock index 93484256..e520ccd1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5360,7 +5360,7 @@ ember-cli-babel-plugin-helpers@^1.0.0, ember-cli-babel-plugin-helpers@^1.1.0, em resolved "https://registry.yarnpkg.com/ember-cli-babel-plugin-helpers/-/ember-cli-babel-plugin-helpers-1.1.1.tgz#5016b80cdef37036c4282eef2d863e1d73576879" integrity sha512-sKvOiPNHr5F/60NLd7SFzMpYPte/nnGkq/tMIfXejfKHIhaiIkYFqX8Z9UFTKWLLn+V7NOaby6niNPZUdvKCRw== -ember-cli-babel@^6.0.0, ember-cli-babel@^6.16.0, ember-cli-babel@^6.6.0, ember-cli-babel@^6.8.0, ember-cli-babel@^6.9.0: +ember-cli-babel@^6.16.0, ember-cli-babel@^6.6.0, ember-cli-babel@^6.8.0: version "6.18.0" resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-6.18.0.tgz#3f6435fd275172edeff2b634ee7b29ce74318957" integrity sha512-7ceC8joNYxY2wES16iIBlbPSxwKDBhYwC8drU3ZEvuPDMwVv1KzxCNu1fvxyFEBWhwaRNTUxSCsEVoTd9nosGA== @@ -6051,13 +6051,6 @@ ember-in-viewport@^4.0.2: dependencies: ember-cli-babel "^7.26.5" -ember-invoke-action@^1.5.0: - version "1.5.1" - resolved "https://registry.yarnpkg.com/ember-invoke-action/-/ember-invoke-action-1.5.1.tgz#b6cad51ee729fc227cdbdba83b2b5486f0fa5834" - integrity sha512-co6Yg9r5qtK4LvZTZHk+u02YLPbnM2c5ZkXvundxEj3V7qdZg7RULfjU09LmohD+rxW5ADZlwgBi/32XIEWTlw== - dependencies: - ember-cli-babel "^6.6.0" - ember-lifeline@^4.1.5: version "4.1.5" resolved "https://registry.yarnpkg.com/ember-lifeline/-/ember-lifeline-4.1.5.tgz#a3db0c2357b533c65e1396c1c1d70609c2cd7276" @@ -6114,16 +6107,6 @@ ember-modifier-manager-polyfill@^1.2.0: ember-cli-typescript "^5.0.0" ember-compatibility-helpers "^1.2.5" -ember-one-way-controls@^3.0.1: - version "3.1.0" - resolved "https://registry.yarnpkg.com/ember-one-way-controls/-/ember-one-way-controls-3.1.0.tgz#5037d024aea0466a1dd787a79fbfd82b5df8c71e" - integrity sha512-SH/BcT7WWUWBuabOZ6TEPLrpG/FxL7MEIcXWjSzA6E0gCsIrB87jJL5uM12cwBjF9o3hEDUN/y5zNu1D8Wfomw== - dependencies: - ember-cli-babel "^6.0.0" - ember-cli-htmlbars "^2.0.1" - ember-invoke-action "^1.5.0" - ember-runtime-enumerable-includes-polyfill "^2.0.0" - ember-power-select@^4.0.0: version "4.1.7" resolved "https://registry.yarnpkg.com/ember-power-select/-/ember-power-select-4.1.7.tgz#eb547dd37448357d8f3fa789db18ddbba43fb8ca" @@ -6209,14 +6192,6 @@ ember-router-generator@^2.0.0: "@babel/traverse" "^7.4.5" recast "^0.18.1" -ember-runtime-enumerable-includes-polyfill@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/ember-runtime-enumerable-includes-polyfill/-/ember-runtime-enumerable-includes-polyfill-2.1.0.tgz#dc6d4a028471e4acc350dfd2a149874fb20913f5" - integrity sha512-au18iI8VbEDYn3jLFZzETnKN5ciPgCUxMRucEP3jkq7qZ6sE0FVKpWMPY/h9tTND3VOBJt6fgPpEBJoJVCUudg== - dependencies: - ember-cli-babel "^6.9.0" - ember-cli-version-checker "^2.1.0" - ember-scrollable@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/ember-scrollable/-/ember-scrollable-1.0.2.tgz#f8f110287ce19a508f292b3b7be3ec5ab3cea0c0"