https://github.com/parloti/ngrx-set
It simplifies the creation of actions for asynchronous requests that can succeed, fail or be aborted.
https://github.com/parloti/ngrx-set
angular ngrx ngrx-store rxjs
Last synced: 7 days ago
JSON representation
It simplifies the creation of actions for asynchronous requests that can succeed, fail or be aborted.
- Host: GitHub
- URL: https://github.com/parloti/ngrx-set
- Owner: parloti
- Created: 2023-06-05T01:26:40.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-28T21:44:32.000Z (6 months ago)
- Last Synced: 2025-10-05T23:24:38.535Z (3 months ago)
- Topics: angular, ngrx, ngrx-store, rxjs
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/ngrx-set
- Size: 1.11 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-angular - ngrx-set - This simplifies the creation of actions for asynchronous requests that can succeed, fail, or be aborted. (State Management / NgRx)
- fucking-awesome-angular - ngrx-set - This simplifies the creation of actions for asynchronous requests that can succeed, fail, or be aborted. (State Management / NgRx)
README
# NgRxSet
It simplifies the creation of actions for asynchronous requests that can succeed, fail or be aborted.
## Usage
```ts
const set = createSet('source', 'name');
store.dispatch(set.dispatch());
store.dispatch(set.success());
store.dispatch(set.failure());
store.dispatch(set.abort());
```
## Examples
More examples at:
[store.ts#creators](projects/example-app/src/app/store.ts#L17)
[example-effects.ts](projects/example-app/src/app/example-effects.ts)
## API
### IAbortCreator
Creator to be used when the request is aborted.
`type IAbortCreator`
`abort({ reason: 'reason' });`
### IFailureCreator
Creator to be used when the request fails.
`type IFailureCreator`
`failure({ error: 'error' });`
### IQueryCreator
Creator to be used when submitting a query to trigger the request.
`type IQueryCreator`
`dispatch({ query: TQuery });`
### IPayloadCreator
Creator to be used when receiving the request payload.
`type IPayloadCreator`
`success({ payload: TPayload });`
### IEmptyCreator
Creator to be used without passing data.
`type IEmptyCreator`
`dispatch();`
`success();`
### ICreatorSet
A set of creators related to a request.
```
interface ICreatorSet<
TDispatch extends ICreator | IEmptyCreator,
TSuccess extends ICreator | IEmptyCreator,
TReasonType extends string = string,
TErrorType extends string = string,
> {
abort: IAbortCreator;
dispatch: TDispatch;
failure: IFailureCreator;
success: TSuccess;
}
```
#### ICreatorSet aliases
When neither dispatch nor success carry data.
```
type IEmptySet<
TSource extends string = string,
TName extends string = string,
> = ICreatorSet<
IEmptyCreator}`>>,
IEmptyCreator}`>>,
IAbortType<`${IType}`>,
IFailureType<`${IType}`>
>;
createSet('source', 'name'): IEmptySet<"source", "name">;
```
When the dispatch action carries data but success does not.
```
type IQuerySet<
TQuery,
TSource extends string,
TName extends string,
> = ICreatorSet<
IQueryCreator}`>>,
IEmptyCreator}`>>,
IAbortType<`${IType}`>,
IFailureType<`${IType}`>
>;
createSet('source', 'name'): IQuerySet;
createSet('source', 'name'): IQuerySet;
```
When the dispatch action does not carry data but success does.
```
type IPayloadSet<
TPayload,
TSource extends string,
TName extends string,
> = ICreatorSet<
IEmptyCreator}`>>,
IPayloadCreator}`>>,
IAbortType<`${IType}`>,
IFailureType<`${IType}`>
>;
createSet('source', 'name'): IPayloadSet;
createSet('source', 'name'): IPayloadSet
```
When both the dispatch and success actions carry data.
```
type IFullSet<
TQuery,
TPayload,
TSource extends string,
TName extends string,
> = ICreatorSet<
IQueryCreator}`>>,
IPayloadCreator}`>>,
IAbortType<`${IType}`>,
IFailureType<`${IType}`>
>;
createSet('source', 'name'): IFullSet>;
createSet('source', 'name'): IFullSet;
```
## Support
If you like `ngrx-set`, please support it:
- [with a star on GitHub](https://github.com/parloti/ngrx-set)
- [with a tweet](https://twitter.com/intent/tweet?text=Check%20ngrx-set%20package%20%23angular%20%23rxjs%20%23ngrx%26url%3Dhttps%3A%2F%2Fgithub.com%2Fparloti%2Fngrx-set)
Thank you!
P.S. If you need help, feel free to
- Contact me on [twitter](https://twitter.com/parloti) or [linkedin](https://www.linkedin.com/in/parloti/)
- [Open an issue](https://github.com/parloti/ngrx-set/issues)