Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It would be nice to have an option to debounce #456

Closed
rsivan opened this issue May 8, 2020 · 4 comments
Closed

It would be nice to have an option to debounce #456

rsivan opened this issue May 8, 2020 · 4 comments

Comments

@rsivan
Copy link

rsivan commented May 8, 2020

My use case is a fast scroll from top to bottom.
It would be nice to skip loading all the images in between.

Thanks.

@tjoskar
Copy link
Owner

tjoskar commented May 10, 2020

I agree. I will take a look.

@tjoskar
Copy link
Owner

tjoskar commented May 24, 2020

This should be possible in the upcoming version 8.0.0-beta.2 (npm install [email protected]). Please try it out and get back to me with what you think.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { debounceTime } from 'rxjs/operators';
import { LazyLoadImageModule, IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';
import { AppComponent } from './app.component';

class LazyLoadImageHooks extends IntersectionObserverHooks {
  getObservable(attributes: Attributes) {
    return super.getObservable(attributes).pipe(debounceTime(1000))
  }
}

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, LazyLoadImageModule.forRoot(LazyLoadImageHooks)],
  bootstrap: [AppComponent],
})
export class MyAppModule {}

Let me know if something is unclear or if it doesn't work for you. The plan is to leave the beta channel in a couple of days.

@tjoskar
Copy link
Owner

tjoskar commented May 29, 2020

I have created a sandbox here where you can try it out: https://codesandbox.io/s/lazy-load-image-with-httpclient-to538?file=/src/app/app.module.ts

Scroll down fast and then slowly up

@tjoskar
Copy link
Owner

tjoskar commented May 29, 2020

Version 8.0.0 is now out.
Let me know if you have any issues or if it does not solve your issue.

@tjoskar tjoskar closed this as completed May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants