Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove enableSync option, require updating table rows manually #804

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 0 additions & 103 deletions addon/-private/sync-array-proxy.js

This file was deleted.

51 changes: 0 additions & 51 deletions addon/classes/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,10 @@ 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';
import { mergeOptionsWithGlobals } from 'ember-light-table/-private/global-options';
import { isNone } from '@ember/utils';
import classic from 'ember-classic-decorator';

const RowSyncArrayProxy = SyncArrayProxy.extend({
serializeContentObjects(objects) {
return Table.createRows(objects);
},

serializeSyncArrayObjects(objects) {
return objects.map((o) => o.content);
},
});

/**
* @module Table
* @private
Expand Down Expand Up @@ -154,9 +143,6 @@ export default class Table extends EmberObject.extend({
* @param {Object} options
* @param {Array} options.columns
* @param {Array} options.rows
* @param {Boolean} options.enableSync If `true`, creates a two way sync
* between the table's rows and the passed rows collection. Also see
* `setRowsSynced(rows)`.
* @param {Object} options.rowOptions Options hash passed through to
* `createRow(content, options)`.
*/
Expand All @@ -177,26 +163,9 @@ export default class Table extends EmberObject.extend({

let _rows = emberArray(Table.createRows(rows, this.rowOptions));

if (this.enableSync) {
_rows = RowSyncArrayProxy.create({
syncArray: rows,
content: _rows,
});
}

this.set('rows', _rows);
},
}) {
destroy() {
super.destroy(...arguments);

let rows = this.rows;

if (rows instanceof RowSyncArrayProxy) {
rows.destroy();
}
}

// Rows

/**
Expand All @@ -210,26 +179,6 @@ export default class Table extends EmberObject.extend({
return this.rows.setObjects(Table.createRows(rows, options));
}

/**
* The same as `setRows`, however the given array is synced, meaning that
* mutating the array also updates the table and vice-versa.
*
* Also see `enableSync` in the constructor options.
*
* @method setRowsSynced
* @param {Array} rows
* @param {Object} options
* @return {Array} rows
*/
setRowsSynced(rows = [], options = {}) {
let _rows = RowSyncArrayProxy.create({
syncArray: rows,
content: emberArray(Table.createRows(rows, options)),
});

return this.set('rows', _rows);
}

/**
* Push the object onto the end of the row array if it is not already present.
* @method addRow
Expand Down
31 changes: 0 additions & 31 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,6 @@ import Row from './classes/Row';
* });
* ```
*
* ## Implicit Row Creation
*
* To enable synchronization between the table's rows and a model, the `enableSync` flag
* must be set to __true__.
*
* ```javascript
* import Table from 'ember-light-table';
*
* const table = Table.create({ columns: columns, rows: model, enableSync: true });
* ```
*
* The `enableSync` options creates a __two way__ sync. This means that any manipulation
* that occurs on the model will also take place on the table's rows collection and vice versa.
*
* To default `enableSync` to always be true, you can add the following in your __config/environment.js__
*
* ```javascript
* module.exports = function(environment) {
* var ENV = {
* // ...
* 'ember-light-table': {
* enableSync: true
* }
* };
*
* // ...
*
* return ENV;
* };
* ```
*
* @module Usage
* @submodule Table Declaration
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/dummy/app/components/base-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { tracked } from '@glimmer/tracking';
export default class BaseTable extends Component {
@service store;

enableSync = true;
model = null;

@tracked canLoadMore = true;
Expand All @@ -30,7 +29,6 @@ export default class BaseTable extends Component {
const table = Table.create({
columns: this.columns,
rows: this.model,
enableSync: this.enableSync,
});
const sortColumn = table.get('allColumns').findBy('valuePath', this.sort);

Expand All @@ -53,7 +51,9 @@ export default class BaseTable extends Component {
sort: this.sort,
dir: this.dir,
});
this.model.pushObjects(records.toArray());
const recordsArray = records.toArray();
this.model.pushObjects(recordsArray);
this.table.addRows(recordsArray);
this.meta = records.meta;
this.canLoadMore = !isEmpty(records);
}
Expand Down
7 changes: 3 additions & 4 deletions tests/dummy/app/components/cookbook/client-side-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import { tracked } from '@glimmer/tracking';
export default class PaginatedTable extends BaseTable {
query = '';

// No need for `enableSync` here
enableSync = false;

model = [];

get sortedModel() {
Expand Down Expand Up @@ -71,7 +68,9 @@ export default class PaginatedTable extends BaseTable {

@restartableTask *fetchRecords() {
const records = yield this.store.query('user', { page: 1, limit: 100 });
this.model.setObjects(records.toArray());
const recordsArray = records.toArray();
this.model.setObjects(recordsArray);

this.meta = records.meta;
yield this.filterAndSortModel.perform();
}
Expand Down
Loading