Skip to content

Commit cfad1e0

Browse files
committed
Removed pagination instance update from the iquiPaginate pipe and replaced it with a new more general use iquiCallback pipe
1 parent 96cd97c commit cfad1e0

File tree

8 files changed

+47
-7
lines changed

8 files changed

+47
-7
lines changed

projects/iqui-ngx/src/lib/_showcase/pages.ts

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import { PhraseShowcaseComponent } from '../data/_showcase';
4747
import { Pagination } from '../data';
4848
import { PaginationShowcaseComponent } from '../data/_showcase';
4949
// Import pipe dependencies
50+
import { CallbackPipe } from '../pipes';
51+
import { CallbackShowcaseComponent } from '../pipes/_showcase';
5052
import { FilterPipe } from '../pipes';
5153
import { FilterShowcaseComponent } from '../pipes/_showcase';
5254
import { SortPipe } from '../pipes';
@@ -100,6 +102,7 @@ const pages = [
100102
]),
101103

102104
new Page('pipes', 'Pipes', 'Pipes', null, [
105+
Page.fromClass(CallbackPipe, CallbackShowcaseComponent),
103106
Page.fromClass(FilterPipe, FilterShowcaseComponent),
104107
Page.fromClass(SortPipe, SortShowcaseComponent),
105108
Page.fromClass(PaginatePipe, PaginateShowcaseComponent),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- Intro -->
2+
<h5>Callback Pipe class</h5>
3+
Passes its input data to the function passed as its only argument when ever the input data changes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Callback pipe showcase
2+
// ----------------------------------------------------------------------------
3+
4+
// Import dependencies
5+
import { Component } from '@angular/core';
6+
7+
// Showcase component
8+
@Component({
9+
templateUrl: `./index.html`,
10+
styleUrls: [`./style.scss`],
11+
})
12+
export class CallbackShowcaseComponent {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:host {
2+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Callback pipe
2+
// ----------------------------------------------------------------------------
3+
4+
// Import dependencies
5+
import { Pipe, PipeTransform } from '@angular/core';
6+
import { Pagination } from '../../data';
7+
8+
/**
9+
* Passes its input data to the function passed as its only argument when ever the input data changes
10+
*/
11+
@Pipe({
12+
name: 'iquiCallback',
13+
})
14+
export class CallbackPipe implements PipeTransform {
15+
public transform(items: any[], callbackFn: (input: any[]) => any[]): any[] {
16+
return callbackFn(items);
17+
}
18+
}

projects/iqui-ngx/src/lib/pipes/Paginate/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ import { Pagination } from '../../data';
1212
name: 'iquiPaginate',
1313
})
1414
export class PaginatePipe implements PipeTransform {
15-
public transform(items: any[], startIndex: number, pageLength: number, paginationInstanceToBeUpdatedWithNewItems?: Pagination): any[] {
16-
// Update data being paginated (if pagination provided)
17-
if (paginationInstanceToBeUpdatedWithNewItems) {
18-
paginationInstanceToBeUpdatedWithNewItems.updateItems(items);
19-
}
15+
public transform(items: any[], startIndex: number, pageLength: number): any[] {
2016
// Return current page range of items
2117
return (items || []).slice(startIndex, startIndex + pageLength);
2218
}

projects/iqui-ngx/src/lib/pipes/_showcase.ts

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { CommonModule } from '@angular/common';
77
import { RouterModule } from '@angular/router';
88

99
// Import showcase components
10+
import { CallbackShowcaseComponent } from './Callback/_showcase';
11+
export { CallbackShowcaseComponent } from './Callback/_showcase';
1012
import { FilterShowcaseComponent } from './Filter/_showcase';
1113
export { FilterShowcaseComponent } from './Filter/_showcase';
1214
import { SortShowcaseComponent } from './Sort/_showcase';
@@ -21,13 +23,15 @@ export { SliceShowcaseComponent } from './Slice/_showcase';
2123
imports: [CommonModule, RouterModule],
2224
declarations: [
2325
// Declare showcasing components
26+
CallbackShowcaseComponent,
2427
FilterShowcaseComponent,
2528
SortShowcaseComponent,
2629
PaginateShowcaseComponent,
2730
SliceShowcaseComponent,
2831
],
2932
exports: [
3033
// Export child components
34+
CallbackShowcaseComponent,
3135
FilterShowcaseComponent,
3236
SortShowcaseComponent,
3337
PaginateShowcaseComponent,

projects/iqui-ngx/src/lib/pipes/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { CommonModule } from '@angular/common';
44
import { OverlayModule } from '@angular/cdk/overlay';
55

66
// Import pipes and (re)export pipes
7+
import { CallbackPipe } from './Callback';
8+
export { CallbackPipe } from './Callback';
79
import { FilterPipe } from './Filter';
810
export { FilterPipe } from './Filter';
911
import { PaginatePipe } from './Paginate';
@@ -19,7 +21,7 @@ export { SortPipe } from './Sort';
1921
*/
2022
@NgModule({
2123
imports: [CommonModule, OverlayModule],
22-
declarations: [FilterPipe, PaginatePipe, SlicePipe, SortPipe],
23-
exports: [FilterPipe, PaginatePipe, SlicePipe, SortPipe],
24+
declarations: [CallbackPipe, FilterPipe, PaginatePipe, SlicePipe, SortPipe],
25+
exports: [CallbackPipe, FilterPipe, PaginatePipe, SlicePipe, SortPipe],
2426
})
2527
export class PipesModule {}

0 commit comments

Comments
 (0)