Releases: e-oz/ngx-collection
4.3.2
4.3.1
4.3.0
4.2.3
New method: fetchItem()
!
This method will check if the item exists in the collection and return it if it does.
If the item does not exist, the request
argument will be used to fetch the item and add it to the collection.
If the option fetchItemRequestFactory
is set, the request
argument is optional.
If both are missing, the resulting Observable will throw an error.
4.2.2
4.2.1
4.2.0
- New (experimental!) methods:
readFrom
andreadManyFrom
. Can be called as part of constructor options. EffectFnMethods
renamed toEffectObservables
, and lost methodsnext
,error
andcomplete
- the same functionality with a less ambiguous API can be achieved withEffectListeners
. This API is considered stable now.
4.1.3
4.1.2
Improved API for createEffect()
listeners, introduced in v4.1.1.
Methods of the function, returned by createEffect()
:
export type EffectFnMethods = {
next: (fn: ((v: unknown) => void)) => void,
error: (fn: ((v: unknown) => void)) => void,
complete: (fn: (() => void)) => void,
next$: Observable<unknown>,
error$: Observable<unknown>,
};
Also, you can set next
listener or an object with listeners as a second argument, when you call an effect:
class Component {
store = inject(Store);
dialog = inject(Dialog);
toasts = inject(Toasts);
changeZipCode(zipCode: string) {
this.store.changeZipCode(zipCode, () => this.dialog.close());
// or:
this.store.changeZipCode(zipCode, {
next: () => this.dialog.close(),
error: () => this.toasts.error('Error, please try again.'),
});
}
}
4.1.1
createEffect()
now returns not just a function, but a function with methods! :)
API is experimental and might change, so it's documented only here for now.
In your store:
import { createEffect } from './create-effect';
class Store extends Collection<Item> {
readonly changeZipCode = createEffect<string>(_ => _.pipe(
// code to change zipcode
));
}
In your component:
class Component {
store = inject(Store);
dialog = inject(Dialog);
changeZipCode(zipCode: string) {
this.store.changeZipCode.nextValue(() => this.dialog.close());
this.store.changeZipCode(zipCode);
}
}
In this example, the dialog window will be closed only after the service response, and only if it was successful.
Alongside nextValue, there are other methods:
export type EffectFnMethods = {
nextValue: (fn: ((v: unknown) => void)) => void,
nextError: (fn: ((v: unknown) => void)) => void,
onNextValue(): Observable<unknown>,
onNextError(): Observable<unknown>,
};
Internally, values and errors will not be saved in memory if you don't use these methods.