Skip to content

Releases: e-oz/ngx-collection

4.1.0

12 Aug 12:29
Compare
Choose a tag to compare

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

23 May 10:07
Compare
Choose a tag to compare

Angular v18 is now supported.

4.0.6

24 Jan 13:15
Compare
Choose a tag to compare
  • Function, returned by createEffect() now accepts Signal<T> | WritableSignal<T> as an argument;
  • createEffect() now has optional configuration argument of type CreateEffectOptions. Here you can pass an injector, configure if function should retry on error (true by default), and pass retry() configuration options. All fields are optional.

4.0.5

08 Dec 13:10
Compare
Choose a tag to compare

Because of PR#53446, one custom equality check function is restored. You can import it as equalPrimitives().

v4.0

24 Nov 16:32
Compare
Choose a tag to compare
  • 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: use setOnFirstItemsRequest().

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, if read() or delete() operations were executed faster than update(), and update() was started earlier, than update() would contain items that were removed by delete(), 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

14 Nov 06:35
Compare
Choose a tag to compare

Method getItemByField() now accepts Signal<T|undefined> as fieldValue.

3.4.2

14 Nov 06:28
Compare
Choose a tag to compare
  • Method setAfterFirstReadHandler() renamed to setOnFirstItemsRequest(). Previous method is not removed, but deprecated.
  • Now it's possible to set onFirstItemsRequest in the constructor (using the options object).

3.4.1

09 Nov 10:56
Compare
Choose a tag to compare

Fix: getItem() and getItemByField() should trigger lazy-loading.

3.4.0 - Lazy loading!

08 Nov 12:30
Compare
Choose a tag to compare

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

10 Oct 13:22
Compare
Choose a tag to compare

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.