This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Collapsible & sticky headers | |
*/ | |
background: #f06; | |
background: linear-gradient(45deg, #f06, yellow); | |
min-height: 100%; | |
* { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"scripts": [ | |
"src/intersection-observer.js" | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit() { // parent component creation | |
// ... | |
this.lazyLoadService.registerAfter(1500); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="list" [@listChild]="noteService.listState"> | |
<my-note class="item" | |
*ngFor="let note of noteService.items$ | async"> | |
</my-note> | |
</div> |
NewerOlder