Skip to content

3.4.0 - Lazy loading!

Compare
Choose a tag to compare
@e-oz e-oz released this 08 Nov 12:30
· 27 commits to main since this release

3.4.0

Lazy loading!

Previously, you could load the first set of items into the collection when collection is initialized, or when your service/component decide to do it.

Now, you can also use lazy loading, using the setAfterFirstReadHandler(handlerFn) - handlerFn will be called once (asynchronously), when $items signal is read for the first time.

Example:

class ExampleService {
  private readonly coll = new Collection();
  private readonly api = inject(ApiService);

  private readonly load = createEffect(_ => _.pipe(
    switchMap(() => this.coll.read({
      request: this.api.getItems()
    }))
  ));

  constructor() {
    this.coll.setAfterFirstReadHandler(() => this.load());
  }
}

It is just an example - it's up to you how your handler will load the first set of items.