3.4.0 - Lazy loading!
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.