Skip to content

Instantly share code, notes, and snippets.

View bob-lee's full-sized avatar

Bob Lee bob-lee

  • MyTrucking.com
  • New Zealand
View GitHub Profile
@bob-lee
bob-lee / dabblet.css
Created February 26, 2021 19:03
Collapsible & sticky headers
/**
* Collapsible & sticky headers
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
* {
"scripts": [
"src/intersection-observer.js"
]
<div class="list" [@listChild]="noteService.listState">
<my-note class="item" #myNote
*ngFor="let note of noteService.items$ | async; let i = index"
(lazyLoad)="myNote.doLoad($event,i)" [url]="note.imageURL" [index]="i">
</my-note>
</div>
export class LazyLoadService {
// ...
private _loadAheadCount = 2; // default 2
get loadAheadCount() { return this._loadAheadCount; }
set loadAheadCount(value: number) {
this._loadAheadCount = value;
}
// announce intersecting index to [lazyLoad] directives
export class LazyLoadDirective implements AfterViewInit, OnDestroy {
// ...
@Input() index = -1;
public ngAfterViewInit() {
// ...
if (this.index !== -1) { // if [index] given, listen to intersecting index
const sub = this._service.announcedIntersection.subscribe(params => {
export class LazyLoadDirective implements AfterViewInit, OnDestroy {
private _url = '';
@Input()
set url(value: string) { // optional
if (!this._url && value) { // url added runtime
this.doRegister();
}
this._url = value;
}
ngOnInit() { // parent component creation
// ...
this.lazyLoadService.registerAfter(1500);
}
export class LazyLoadDirective implements AfterViewInit, OnDestroy {
public ngAfterViewInit() {
if (this._service.delayMsec > 0) { // register later
const sub = this._service.announcedOrder.pipe(first()).subscribe(_ => this.doRegister());
this._subscription.add(sub);
} else { // register now (default)
this.doRegister();
}
}
export class LazyLoadService {
delayMsec = 0;
// announce order to [lazyLoad] directives
private order$ = new Subject<string>();
announcedOrder = this.order$.asObservable();
announceOrder(name: string) {
this.order$.next(name);
}
<div class="list" [@listChild]="noteService.listState">
<my-note class="item"
*ngFor="let note of noteService.items$ | async">
</my-note>
</div>