Skip to content

Commit 5291ec0

Browse files
committed
Adapter.clip demo
1 parent bb6cf3d commit 5291ec0

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

demo/app/app.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { DemoAppendPrependSyncComponent } from './samples/adapter/append-prepend
3535
import { DemoIsLoadingExtendedComponent } from './samples/adapter/is-loading-extended.component';
3636
import { DemoCheckSizeComponent } from './samples/adapter/check-size.component';
3737
import { DemoRemoveComponent } from './samples/adapter/remove.component';
38+
import { DemoClipComponent } from './samples/adapter/clip.component';
3839
import { DemoDatasourceSignaturesComponent } from './samples/datasource/datasource-signatures.component';
3940
import { DemoBidirectionalUnlimitedDatasourceComponent } from './samples/datasource/bidirectional-unlimited-datasource.component';
4041
import { DemoLimitedDatasourceComponent } from './samples/datasource/limited-datasource.component';
@@ -76,6 +77,7 @@ import { AppRoutingModule } from './app-routing.module';
7677
DemoIsLoadingExtendedComponent,
7778
DemoCheckSizeComponent,
7879
DemoRemoveComponent,
80+
DemoClipComponent,
7981
DemoDatasourceSignaturesComponent,
8082
DemoBidirectionalUnlimitedDatasourceComponent,
8183
DemoLimitedDatasourceComponent,

demo/app/samples/adapter.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ <h1>Angular UI Scroll Adapter Demos</h1>
3232
<app-demo-append-prepend-sync></app-demo-append-prepend-sync>
3333
<app-demo-check-size></app-demo-check-size>
3434
<app-demo-remove></app-demo-remove>
35+
<app-demo-clip></app-demo-clip>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<app-demo [datasource]="datasource" [context]="demoContext" [sources]="sources">
2+
<div actions style="display: flex">
3+
<button (click)="doClip()">Clip</button>
4+
</div>
5+
6+
<div description>
7+
<p>
8+
<em>Adapter.clip</em> is another <em>Adapter</em> API method
9+
allowing to remove out-of-viewport items on demand.
10+
Commonly, the <em>uiScroll</em> runs the clipping procedure
11+
each time new items are fetched after scrolling.
12+
Also, the <em>uiScroll</em> clipps old items from a side of the viewport
13+
that is opposite to a side where new items appear.
14+
This is one of the core parts of the virtualization concept.
15+
By invoking the <em>Adapter.clip</em> method
16+
we are telling the <em>uiScroll</em> to run this process immediately
17+
and remove items that are out of the visible part of the viewport
18+
in both directions or in specific direction.
19+
</p>
20+
<p>
21+
This could be useful when we enlarge the list of items manually,
22+
via <em>Adapter.append</em> or <em>.prepend</em> methods.
23+
For example, we appended 100 new items and started scrolling down, in forward direction.
24+
We might want the items that exit the viewport in backward direction to be clipped.
25+
Such a clipping will occur automatically only when we reach the bottom line of the buffer
26+
and new items are fetched and rendered in forward direction.
27+
If we don't want to wait, we just call <em>Adapter.clip</em>.
28+
</p>
29+
<p>
30+
This demo implements some artificial but quite illustrative case.
31+
Here we disabled virtualization by turning on the <em>infinite</em> setting.
32+
Clipping will never happen automatically.
33+
We see how the DOM elements counter value is getting bigger and bigger as we scroll on and on.
34+
By pressiing the "Clip" button, we let only 20-21 items to survive.
35+
This way a kind of manual virtualization could be implemented.
36+
</p>
37+
<p>
38+
The method has an argument object that allows to run clipping process
39+
only in one direction:
40+
</p>
41+
<pre>{{clipOptionsDescription}}</pre>
42+
<p>
43+
So, if we call <em>Adapter.clip({{clipOptionsSample}})</em>,
44+
only ithose tems that are out of the bottom border of the visible part of the viewport
45+
will be clipped out.
46+
</p>
47+
</div>
48+
</app-demo>
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { Component } from '@angular/core';
2+
3+
import { DemoContext, DemoSources, DemoSourceType } from '../../shared/interfaces';
4+
import { datasourceGetCallbackInfinite } from '../../shared/datasource-get';
5+
6+
import { Datasource } from '../../../../public_api'; // from 'ngx-ui-scroll';
7+
8+
@Component({
9+
selector: 'app-demo-clip',
10+
templateUrl: './clip.component.html'
11+
})
12+
export class DemoClipComponent {
13+
14+
demoContext: DemoContext = <DemoContext>{
15+
scope: 'adapter',
16+
title: `Clip`,
17+
titleId: `clip`,
18+
viewportId: `clip-viewport`,
19+
count: 0,
20+
log: ''
21+
};
22+
23+
datasource = new Datasource({
24+
get: datasourceGetCallbackInfinite(this.demoContext),
25+
settings: {
26+
infinite: true
27+
},
28+
devSettings: {
29+
debug: true,
30+
logProcessRun: true
31+
}
32+
});
33+
34+
sources: DemoSources = [{
35+
name: DemoSourceType.Component,
36+
text: `datasource = new Datasource ({
37+
get: (index, count, success) => {
38+
const data = [];
39+
for (let i = index; i <= index + count - 1; i++) {
40+
data.push({ id: i, text: 'item #' + i });
41+
}
42+
success(data);
43+
},
44+
settings: {
45+
infinite: true
46+
}
47+
});
48+
49+
doClip() {
50+
this.datasource.adapter.clip();
51+
}`
52+
}, {
53+
active: true,
54+
name: DemoSourceType.Template,
55+
text: `<button (click)="doClip()">Clip</button>
56+
57+
<div class="viewport">
58+
<div *uiScroll="let item of datasource">
59+
<div class="item">{{item.text}}</div>
60+
</div>
61+
</div>`
62+
}, {
63+
name: DemoSourceType.Styles,
64+
text: `.viewport {
65+
width: 150px;
66+
height: 250px;
67+
overflow-y: auto;
68+
overflow-anchor: none;
69+
}
70+
.item {
71+
font-weight: bold;
72+
height: 25px;
73+
}`
74+
}];
75+
76+
clipOptionsDescription = ` ClipOptions {
77+
forwardOnly?: boolean;
78+
backwardOnly?: boolean;
79+
}`;
80+
81+
clipOptionsSample = `{ forwardOnly: true }`;
82+
83+
doClip() {
84+
this.datasource.adapter.clip();
85+
}
86+
87+
}

0 commit comments

Comments
 (0)