Skip to content

Commit

Permalink
Import computed macros directly (#790)
Browse files Browse the repository at this point in the history
* Refactor computeds

* Update more computeds
  • Loading branch information
RobbieTheWagner authored Jul 13, 2022
1 parent 092b04c commit dcaf601
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 73 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions addon/classes/Column.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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
Expand Down
29 changes: 15 additions & 14 deletions addon/classes/Table.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -46,65 +47,65 @@ 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
* @type {Ember.Array}
*/
sortableColumns: computed
.filterBy('visibleColumns', 'sortable', true)
.readOnly(),
sortableColumns: filterBy('visibleColumns', 'sortable', true).readOnly(),

/**
* @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
* @type {Ember.Array}
*/
responsiveHiddenColumns: computed
.filterBy('allColumns', 'responsiveHidden', true)
.readOnly(),
responsiveHiddenColumns: filterBy(
'allColumns',
'responsiveHidden',
true
).readOnly(),

/**
* @property visibleColumns
* @type {Ember.Array}
*/
visibleColumns: computed.filterBy('allColumns', 'isHidden', false).readOnly(),
visibleColumns: filterBy('allColumns', 'isHidden', false).readOnly(),

/**
* @property visibleColumnGroups
Expand Down
3 changes: 2 additions & 1 deletion addon/components/cells/base.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions addon/components/columns/base.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 () {
Expand All @@ -53,7 +54,7 @@ const Column = Component.extend(DraggableColumnMixin, {
* @property label
* @type {String}
*/
label: computed.oneWay('column.label'),
label: oneWay('column.label'),

/**
* @property table
Expand Down
3 changes: 2 additions & 1 deletion addon/components/light-table.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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`
Expand Down
7 changes: 4 additions & 3 deletions addon/components/lt-body.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions addon/components/lt-row.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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({
Expand Down
9 changes: 5 additions & 4 deletions addon/mixins/table-header.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions tests/dummy/app/components/base-table.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,

Expand Down
9 changes: 4 additions & 5 deletions tests/dummy/app/components/cookbook/client-side-table.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion tests/dummy/app/components/rows/selectable-table.js
Original file line number Diff line number Diff line change
@@ -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 [
Expand Down
27 changes: 1 addition & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit dcaf601

Please sign in to comment.