Skip to content

Commit

Permalink
fix(ngTableEventsChannel): event callbacks defines incorrect params
Browse files Browse the repository at this point in the history
afterDataSorted and afterDataFiltered defined with wrong params.

The publisher parameter should be the `NgTableParams` instancefor whom the event relates and should the first parameter.

BREAKING CHANGE:

* changed signatures of `afterDataSorted` + `afterDataFiltered` events

Previously:

```ts
(publisher: IDefaultGetData<T>, params: NgTableParams<T>, newData: DataResult<T>[] ): any
```

Now:

```ts
(publisher: NgTableParams<T>, newData: DataResult<T>[] ): any
```
  • Loading branch information
ccrowhurstram committed Dec 6, 2016
1 parent 71dddea commit b7a2aa6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/core/data/ngTableDefaultGetData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export class NgTableDefaultGetDataProvider implements IServiceProvider {
function ngTableDefaultGetData<T>($filter: IFilterService, ngTableEventsChannel: NgTableEventsChannel): IDefaultGetData<T> {

const defaultDataOptions = { applyFilter: true, applySort: true, applyPaging: true };
const self = this;

(getData as IDefaultGetData<T>).applyPaging = applyPaging;
(getData as IDefaultGetData<T>).getFilterFn = getFilterFn;
Expand Down Expand Up @@ -122,10 +121,10 @@ export class NgTableDefaultGetDataProvider implements IServiceProvider {
const options = ng1.extend({}, defaultDataOptions, params.settings().dataOptions);

const fData = options.applyFilter ? applyFilter(data, params) : data;
ngTableEventsChannel.publishAfterDataFiltered(self, params, fData);
ngTableEventsChannel.publishAfterDataFiltered(params, fData);

const orderedData = options.applySort ? applySort(fData, params) : fData;
ngTableEventsChannel.publishAfterDataSorted(self, params,orderedData);
ngTableEventsChannel.publishAfterDataSorted(params,orderedData);

return options.applyPaging ? applyPaging(orderedData, params) : orderedData;
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/ngTableEventsChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export interface IPagesChangedListener {
* Signature of the event hander that is registered to receive the *afterDataFiltered* event
*/
export interface IAfterDataFilteredListener<T> {
(publisher: IDefaultGetData<T>, params: NgTableParams<T>, newData: DataResult<T>[] ): any
(publisher: NgTableParams<T>, newData: DataResult<T>[] ): any
}
/**
* Signature of the event hander that is registered to receive the *afterDataSorted* event
*/
export interface IAfterDataSortedListener<T> {
(publisher: IDefaultGetData<T>, params: NgTableParams<T>, newData: DataResult<T>[] ): any
(publisher: NgTableParams<T>, newData: DataResult<T>[] ): any
}

/**
Expand Down Expand Up @@ -207,8 +207,8 @@ export interface NgTableEventsChannel {
publishAfterReloadData<T>(publisher: NgTableParams<T>, newData: T[], oldData: T[]): void;
publishDatasetChanged<T>(publisher: NgTableParams<T>, newDataset: T[], oldDataset: T[]): void;
publishPagesChanged<T>(publisher: NgTableParams<T>, newPages: IPageButton[], oldPages: IPageButton[]): void;
publishAfterDataFiltered<T>(publisher: IDefaultGetData<T>, params: NgTableParams<T>, newData: T[]): void;
publishAfterDataSorted<T>(publisher: IDefaultGetData<T>, params: NgTableParams<T>, newData: T[]): void;
publishAfterDataFiltered<T>(publisher: NgTableParams<T>, newData: T[]): void;
publishAfterDataSorted<T>(params: NgTableParams<T>, newData: T[]): void;
}

export class NgTableEventsChannel {
Expand Down
10 changes: 5 additions & 5 deletions test/tableParamsSpec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ describe('NgTableParams', () => {

describe('general pub/sub mechanics', () => {

const supportedEvents = ['DatasetChanged', 'AfterReloadData', 'PagesChanged', 'AfterCreated'];
const supportedEvents = ['DatasetChanged', 'AfterReloadData', 'PagesChanged', 'AfterCreated', 'AfterDataFiltered', 'AfterDataSorted'];

it('should be safe to publish event when no subscribers', () => {

Expand Down Expand Up @@ -2160,7 +2160,7 @@ describe('NgTableParams', () => {
describe('afterDataFiltered', () => {
it('should fire when a reload completes - no filter', () => {
// given
ngTableEventsChannel.onAfterDataFiltered((getData, params, newVal) => {
ngTableEventsChannel.onAfterDataFiltered((params, newVal) => {
actualPublisher = params;
actualEventArgs = [newVal];
});
Expand All @@ -2178,7 +2178,7 @@ describe('NgTableParams', () => {

it('should fire when a reload completes and the data is filtered', () => {
// given
ngTableEventsChannel.onAfterDataFiltered((getData, params, newVal) => {
ngTableEventsChannel.onAfterDataFiltered((params, newVal) => {
actualPublisher = params;
actualEventArgs = [newVal];
});
Expand All @@ -2201,7 +2201,7 @@ describe('NgTableParams', () => {
describe('afterDataSorted', () => {
it('should fire when a reload completes - no order', () => {
// given
ngTableEventsChannel.onAfterDataSorted((getData, params, newVal) => {
ngTableEventsChannel.onAfterDataSorted((params, newVal) => {
actualPublisher = params;
actualEventArgs = [newVal];
});
Expand All @@ -2219,7 +2219,7 @@ describe('NgTableParams', () => {

it('should fire when a reload completes and the data is filtered', () => {
// given
ngTableEventsChannel.onAfterDataSorted((getData, params, newVal) => {
ngTableEventsChannel.onAfterDataSorted((params, newVal) => {
actualPublisher = params;
actualEventArgs = [newVal];
});
Expand Down

0 comments on commit b7a2aa6

Please sign in to comment.