1 | import { Pipe } from "@angular/core";
|
2 | import * as i0 from "@angular/core";
|
3 | import * as i1 from "./pagination.service";
|
4 | const LARGE_NUMBER = Number.MAX_SAFE_INTEGER;
|
5 | export class PaginatePipe {
|
6 | constructor(service) {
|
7 | this.service = service;
|
8 | // store the values from the last time the pipe was invoked
|
9 | this.state = {};
|
10 | }
|
11 | transform(collection, args) {
|
12 | // When an observable is passed through the AsyncPipe, it will output
|
13 | // `null` until the subscription resolves. In this case, we want to
|
14 | // use the cached data from the `state` object to prevent the NgFor
|
15 | // from flashing empty until the real values arrive.
|
16 | if (!(collection instanceof Array)) {
|
17 | let _id = args.id || this.service.defaultId();
|
18 | if (this.state[_id]) {
|
19 | return this.state[_id].slice;
|
20 | }
|
21 | else {
|
22 | return collection;
|
23 | }
|
24 | }
|
25 | let serverSideMode = args.totalItems && args.totalItems !== collection.length;
|
26 | let instance = this.createInstance(collection, args);
|
27 | let id = instance.id;
|
28 | let start, end;
|
29 | let perPage = instance.itemsPerPage;
|
30 | let emitChange = this.service.register(instance);
|
31 | if (!serverSideMode && collection instanceof Array) {
|
32 | perPage = +perPage || LARGE_NUMBER;
|
33 | start = (instance.currentPage - 1) * perPage;
|
34 | end = start + perPage;
|
35 | let isIdentical = this.stateIsIdentical(id, collection, start, end);
|
36 | if (isIdentical) {
|
37 | return this.state[id].slice;
|
38 | }
|
39 | else {
|
40 | let slice = collection.slice(start, end);
|
41 | this.saveState(id, collection, slice, start, end);
|
42 | this.service.change.emit(id);
|
43 | return slice;
|
44 | }
|
45 | }
|
46 | else {
|
47 | if (emitChange) {
|
48 | this.service.change.emit(id);
|
49 | }
|
50 | // save the state for server-side collection to avoid null
|
51 | // flash as new data loads.
|
52 | this.saveState(id, collection, collection, start, end);
|
53 | return collection;
|
54 | }
|
55 | }
|
56 | /**
|
57 | * Create an PaginationInstance object, using defaults for any optional properties not supplied.
|
58 | */
|
59 | createInstance(collection, config) {
|
60 | this.checkConfig(config);
|
61 | return {
|
62 | id: config.id != null ? config.id : this.service.defaultId(),
|
63 | itemsPerPage: +config.itemsPerPage || 0,
|
64 | currentPage: +config.currentPage || 1,
|
65 | totalItems: +config.totalItems || collection.length
|
66 | };
|
67 | }
|
68 | /**
|
69 | * Ensure the argument passed to the filter contains the required properties.
|
70 | */
|
71 | checkConfig(config) {
|
72 | const required = ['itemsPerPage', 'currentPage'];
|
73 | const missing = required.filter(prop => !(prop in config));
|
74 | if (0 < missing.length) {
|
75 | throw new Error(`PaginatePipe: Argument is missing the following required properties: ${missing.join(', ')}`);
|
76 | }
|
77 | }
|
78 | /**
|
79 | * To avoid returning a brand new array each time the pipe is run, we store the state of the sliced
|
80 | * array for a given id. This means that the next time the pipe is run on this collection & id, we just
|
81 | * need to check that the collection, start and end points are all identical, and if so, return the
|
82 | * last sliced array.
|
83 | */
|
84 | saveState(id, collection, slice, start, end) {
|
85 | this.state[id] = {
|
86 | collection,
|
87 | size: collection.length,
|
88 | slice,
|
89 | start,
|
90 | end
|
91 | };
|
92 | }
|
93 | /**
|
94 | * For a given id, returns true if the collection, size, start and end values are identical.
|
95 | */
|
96 | stateIsIdentical(id, collection, start, end) {
|
97 | let state = this.state[id];
|
98 | if (!state) {
|
99 | return false;
|
100 | }
|
101 | let isMetaDataIdentical = state.size === collection.length &&
|
102 | state.start === start &&
|
103 | state.end === end;
|
104 | if (!isMetaDataIdentical) {
|
105 | return false;
|
106 | }
|
107 | return state.slice.every((element, index) => element === collection[start + index]);
|
108 | }
|
109 | }
|
110 | PaginatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.9", ngImport: i0, type: PaginatePipe, deps: [{ token: i1.PaginationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
111 | PaginatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.3.9", ngImport: i0, type: PaginatePipe, name: "paginate", pure: false });
|
112 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.9", ngImport: i0, type: PaginatePipe, decorators: [{
|
113 | type: Pipe,
|
114 | args: [{
|
115 | name: 'paginate',
|
116 | pure: false
|
117 | }]
|
118 | }], ctorParameters: function () { return [{ type: i1.PaginationService }]; } });
|
119 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFnaW5hdGUucGlwZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL25neC1wYWdpbmF0aW9uL3NyYy9saWIvcGFnaW5hdGUucGlwZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUMsSUFBSSxFQUFDLE1BQU0sZUFBZSxDQUFDOzs7QUFJbkMsTUFBTSxZQUFZLEdBQUcsTUFBTSxDQUFDLGdCQUFnQixDQUFDO0FBdUI3QyxNQUFNLE9BQU8sWUFBWTtJQUtyQixZQUFvQixPQUEwQjtRQUExQixZQUFPLEdBQVAsT0FBTyxDQUFtQjtRQUg5QywyREFBMkQ7UUFDbkQsVUFBSyxHQUFnQyxFQUFFLENBQUM7SUFHaEQsQ0FBQztJQUVNLFNBQVMsQ0FBNkIsVUFBYSxFQUFFLElBQXNCO1FBRTlFLHFFQUFxRTtRQUNyRSxtRUFBbUU7UUFDbkUsbUVBQW1FO1FBQ25FLG9EQUFvRDtRQUNwRCxJQUFJLENBQUMsQ0FBQyxVQUFVLFlBQVksS0FBSyxDQUFDLEVBQUU7WUFDaEMsSUFBSSxHQUFHLEdBQUcsSUFBSSxDQUFDLEVBQUUsSUFBSSxJQUFJLENBQUMsT0FBTyxDQUFDLFNBQVMsRUFBRSxDQUFDO1lBQzlDLElBQUksSUFBSSxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsRUFBRTtnQkFDakIsT0FBTyxJQUFJLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDLEtBQVUsQ0FBQzthQUNyQztpQkFBTTtnQkFDSCxPQUF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lW2lkXSA9IHtcclxuICAgICAgICAgICAgY29sbGVjdGlvbixcclxuICAgICAgICAgICAgc2l6ZTogY29sbGVjdGlvbi5sZW5ndGgsXHJcbiAgICAgICAgICAgIHNsaWNlLFxyXG4gICAgICAgICAgICBzdGFydCxcclxuICAgICAgICAgICAgZW5kXHJcbiAgICAgICAgfTtcclxuICAgIH1cclxuXHJcbiAgICAvKipcclxuICAgICAqIEZvciBhIGdpdmVuIGlkLCByZXR1cm5zIHRydWUgaWYgdGhlIGNvbGxlY3Rpb24sIHNpemUsIHN0YXJ0IGFuZCBlbmQgdmFsdWVzIGFyZSBpZGVudGljYWwuXHJcbiAgICAgKi9cclxuICAgIHByaXZhdGUgc3RhdGVJc0lkZW50aWNhbChpZDogc3RyaW5nLCBjb2xsZWN0aW9uOiBBcnJheUxpa2U8YW55Piwgc3RhcnQ6IG51bWJlciwgZW5kOiBudW1iZXIpOiBib29sZWFuIHtcclxuICAgICAgICBsZXQgc3RhdGUgPSB0aGlzLnN0YXRlW2lkXTtcclxuICAgICAgICBpZiAoIXN0YXRlKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBmYWxzZTtcclxuICAgICAgICB9XHJcbiAgICAgICAgbGV0IGlzTWV0YURhdGFJZGVudGljYWwgPSBzdGF0ZS5zaXplID09PSBjb2xsZWN0aW9uLmxlbmd0aCAmJlxyXG4gICAgICAgICAgICBzdGF0ZS5zdGFydCA9PT0gc3RhcnQgJiZcclxuICAgICAgICAgICAgc3RhdGUuZW5kID09PSBlbmQ7XHJcblxyXG4gICAgICAgIGlmKCFpc01ldGFEYXRhSWRlbnRpY2FsKSB7XHJcbiAgICAgICAgICAgIHJldHVybiBmYWxzZTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIHJldHVybiAoc3RhdGUuc2xpY2UgYXMgQXJyYXk8YW55PikuZXZlcnkoKGVsZW1lbnQsIGluZGV4KSA9PiBlbGVtZW50ID09PSBjb2xsZWN0aW9uW3N0YXJ0ICsgaW5kZXhdKTtcclxuICAgIH1cclxufVxyXG4iXX0= |
\ | No newline at end of file |