Releases: e-oz/ngx-collection
4.1.0
Sometimes we know in advance the IDs of items we read, and it can be quite useful to know that these items are being read.
Now, the methods read()
, readOne()
, and readMany()
accept a parameter item
/items
, where you can pass partial items:
coll.read({
request: req,
items: [{id: 1}, {id: 2}]
});
This will instantly add {id: 1}
and {id: 2}
to $readingItems
, but not to $items
(because they are not in the collection yet).
Params should be objects that have at least the ID field (the field or multiple fields that the comparator will use to find the item). The object can also have any other fields - they will be ignored.
A new method, isItemReading()
, will return a Signal<boolean>
- you can check (reactively) if an item with a specific ID is being read.
The method isItemProcessing()
will now also look for an item in $readingItems
(in addition to previous states).
And a new helper method to quickly convert an array of IDs into partial items:
idsToPartialItems(ids: unknown[], field: string): Partial<T>[]
4.0.7
4.0.6
- Function, returned by
createEffect()
now acceptsSignal<T> | WritableSignal<T>
as an argument; createEffect()
now has optional configuration argument of typeCreateEffectOptions
. Here you can pass an injector, configure if function should retry on error (true by default), and passretry()
configuration options. All fields are optional.
4.0.5
v4.0
- Angular v17.1.0-next is supported;
- Minimum supported version of Angular is v17.0.0 (stable).
BREAKING CHANGES
- Status pipes removed: it's quite easy to read status from the collection directly in the template;
- Custom equality functions for Angular Signals removed: this library only operates on immutable data structures, and was using these functions only to guarantee updates even when items were mutated outside. In Angular v17.1 custom equality functions are ignored for mutable structures, so they are useless even as a tool for other parts of your application;
getTrackByFieldFn()
helper is removed: with Angular v17 built-in control flow, it is not needed anymore;setAfterFirstReadHandler()
is removed: usesetOnFirstItemsRequest()
.
Fixes
$updatingItems
,$deletingItems
,$refreshingItems
,$mutatingItems
,$processingItems
will only contain items that currently exist in the$items
list. Previously, they could potentially contain non-existing items for a short time. For example, ifread()
ordelete()
operations were executed faster thanupdate()
, andupdate()
was started earlier, thanupdate()
would contain items that were removed bydelete()
, until its (update()
) request is not completed. It was quite difficult to achieve (and even more difficult to notice), but now it's fixed;$mutatingItems
and$processingItems
now contain unique items only. Previously, it was theoretically possible to have duplicates there if some items were being removed and updated simultaneously.
3.4.3
3.4.2
3.4.1
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.
v3.3.2
As preparation for this change in Angular Signals, collection.$items
now uses the first version of Angular Signals' default equality function. This function will always treat items as non-equal, so the $items
signal will send a notification even if items still point to the same objects after the collection was mutated. This library treats items as immutable structures and will not compare them.